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, 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
Hi Georgi,
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, 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;