I am trying to get the datagrid inside the first TilePane in XamWebTileView. I am trying different ways but I have no luck. Can you advise me how to do it?
TilePane tp = TileView1.Items[0] as TilePane;Grid grid = tp.FindName("Grid1") as Grid;DataGrid dg = tp.FindName("DataGridPanel1") as DataGrid;
Both grid and dg are null??
Thanks,Frank
Hi Georgi,
In my case, StackPanel is defined within a Template and this template is applied to the TilePane. I want to set XamWebChart's height and width. Chart's height and width are not changing as per the (state)changes of XamWebTileView. Will you let me know, how to achieve this. No where, i hardcoded chart's height or width.
and please let me know how to fetch internal controls details, as you said using GetTemplateChild() or VisualTreeHelper; so that i will try to set Height and Width using the retrieved chart control.
Thank you
Ashok
<DataTemplate x:Key="UserTemplateMaximized">
<StackPanel>
<TextBlock ... />
<igChart:XamWebChart ...></igChart:XamWebChart>
</StackPanel>
</DataTemplate>
Hi Frank, FindName and VisualTreeHelper work only when the element is added to the visual tree.You can use FindName in LaoutUpdated eventhandler:<igTV:TilePane x:Name="tile1" Key="Tile1" LayoutUpdated="tile1_LayoutUpdated"> <Grid> <Button x:Name="Button1" Click="Button1_Click" Content="Button1"/> </Grid></igTV:TilePane>private void tile1_LayoutUpdated(object sender, EventArgs e){ if (Button1 == null) { tile1 = tileView1.Items["Tile1"]; Button1 = tile1.FindName("Button1") as Button; } tile1.LayoutUpdated -= tile1_LayoutUpdated;}
Another way is:Button1 = ((tile1.Content) as Grid).Children[0] as Button;Regards,Marin
If your case is the code above, you could obtain a reference to the DataGrid by getting TilePane's content:
DataGrid dg = TilePane1.Content as DataGrid;
I tried using VisualTreeHelper class but still I have no luck to get the object inside TilePage. Please see below for example. Do you have working sample code that you can share? Thanks.
<
UserControl ..>
Hi, Frank
If the Grid and the DataGrid are defined within a Template and this template is applied to the TilePane (e.g. as TilePane's ContentTemplate), you'll not be able to obtain a reference to those objects using the FindName method. If that's the case, you could try using GetTemplateChild() method instead or you could use the VisualTreeHelper class to reach these objects.
Hope that helps