Hello,
I set ContentTemplate for different states in MaximizedStateChanging event. I have a grid in Maximized template and I have to find it when state is changed. And that's what I got:
1. State changes from any state to Maximized (that's when I need to find a grid). Search returns null.
2. State changes from Maximized to any state. Search returns valid grid.
Looks like TilePane first changes state and runs all "MaximizedState..." events, and after that it initializes child controls. Right? I need that grid exactly when pane state changes to Maximized. Which event should I subscribe to?
Thanks.
Hi,You can try this in MaximizedStateChanged eventhandler, but I'm not sure if I understand your question correctly. Could you post a samle code?This code changes the ContentTemplate of a tile in maximized state:TilePane tile = e.Element as TilePane;if (e.NewState == TileState.Maximized) tile.ContentTemplate = this.Resources["maxTemplate"] as DataTemplate;else tile.ContentTemplate = null;
Marin
That's about my poor English :)
This is exactly what I do but I don't load DataTemplate from resources, I just read them with XamlReader from xml file.
switch (e.NewState)
{
case TileState.Normal:
pane.ContentTemplate = GetTileTemplate(TileState.Normal, null);
break;
case TileState.Minimized:
pane.ContentTemplate = GetTileTemplate(TileState.Minimized, null);
case TileState.Maximized:
pane.ContentTemplate = GetTileTemplate(TileState.Maximized, (List<ZLink>)pane.Tag);
default:
}
This is how I search a grid within template:
Grid grid = pane.FindControlByName<Grid>("CardGrid");
and searching method:
public static T FindControlByName<T>(this FrameworkElement element, string name) where T: FrameworkElement
if (element == null) return null;
if (element.Name == name && element.GetType() == typeof(T)) return (T)element;
FrameworkElement foundElement = null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
FrameworkElement visual = VisualTreeHelper.GetChild(element, i) as FrameworkElement;
foundElement = visual.FindControlByName<T>(name);
if (foundElement != null)
return (T)foundElement;
When I lookup this variable in TileState.Maximized case, it's always null. I tried to do that in MaximizedStateChanged handler but this is also always null
TilePane pane = (TilePane)e.Element; // and so on
I don't know if this matters, but I have changed TilePane's style and I put content to ToggleButton.Content:
<ToggleButton x:Name="MaximizedStateToggleButton" VerticalAlignment="Stretch" IsChecked="false" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Padding="0">
<ig:Commanding.Command>
<igTileView:TilePaneCommandSource EventName="Click" Parameter="Toggle" CommandType="Maximize"/>
</ig:Commanding.Command>
<ToggleButton.Content>
<ContentPresenter x:Name="contentContentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Grid.Row="0" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Grid.Column="0"/>
</ToggleButton.Content>
</ToggleButton>
You are using VisualTreeHelper, but at this time the Grid does not exist in the VisualTree.Call pane.UpdateLayout before pane.FindControlByName or call the FindControlByName laterMarin