Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Accessing a webBrowser element in a TilePane object
posted

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.

Parents
No Data
Reply
  • 3071
    posted

    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

Children
No Data