Ok, I have a WebBrowser object that is part of the Template that I load when a pane is maximized. How can I access it to set it's NavigateToString property?
I've tried the following code in the TileView's Maximized State Changing Property (wbNew is the name of the webBrowser control in the template):
TilePane pane = e.Element as TilePane;
switch (e.NewState)
{
case TileState.Maximized:
pane.ContentTemplate = this.Resources["MaxTemp"] as DataTemplate;
WebBrowser wb = pane.FindName("wbNew") as WebBrowser;
if (wb != null)
wb.NavigateToString("<iframe src=\"http://es.infragistics.com\" width=100% height=100%></iframe>");
}
break;
FindName doesn't return anything, so it never fires the NavigateToString line. Is there a different place I should put this? Or is there a different way to get the control?
I'm still a relative newbie to Silverlight, so any help would be greatly appreciated.
Hi,The FindName method returns null for elements in a data template.You have to use the VisualTreeHelper or you can add some event-handlers to element inside a data template. This example shows how to get the control from a data template:<DataTemplate x:Key="maximizedTemplate" Loaded="StackPanel_Loaded"> <StackPanel> <TextBlock x:Name="txtMaximized" Text="Maximized"/> </StackPanel></DataTemplate>private void StackPanel_Loaded(object sender, RoutedEventArgs e){ object o = (sender as FrameworkElement).FindName("txtMaximized"); (o as TextBlock).Text = "The template is loaded.";}Regards,Marin
Looks like I wasn't taking the proper path to get to the object. I had a couple StackPanels to transverse first.