locked
WebView in Popup / User Control not working RRS feed

  • Question

  • I'm trying to implement a User Control which hosts a WebViewer (the User Control is a child of a PopUp) to no avail!

    The User Control XAML is

    <Grid Background="LightGray">
     <StackPanel>
       <Button Click="Button_Click">Go to microsoft.com</Button>
      <WebView x:Name="webView"></WebView>
     </StackPanel>
    </Grid>

    The C# code behind is:

    public sealed partial class Help : UserControl
    {
     public Help()
     {
        this.InitializeComponent();
     }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
      webView.Navigate(new Uri(@"http://microsoft.com"));
    }
    }

    Clicking the button does not display the web page. This works if WebView is in a page.

    Is there a problem with WebView in a User Control or is it because the User Control's parent is PopUp? Or am I going crazy?

    As always any help will be gratefully received.

    Friday, January 10, 2014 6:13 PM

Answers

  • It's because your WebView doesn't have a Width or a Height.  StackPanel smashes it down to nothing.  Add Height and Width of 200 to it, it shows up fine.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by Dave SmitsMVP Friday, January 10, 2014 9:38 PM
    • Marked as answer by Ted Weston Sunday, January 12, 2014 6:51 PM
    Friday, January 10, 2014 9:14 PM
    Moderator

All replies

  • It's because your WebView doesn't have a Width or a Height.  StackPanel smashes it down to nothing.  Add Height and Width of 200 to it, it shows up fine.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by Dave SmitsMVP Friday, January 10, 2014 9:38 PM
    • Marked as answer by Ted Weston Sunday, January 12, 2014 6:51 PM
    Friday, January 10, 2014 9:14 PM
    Moderator
  • Thank you for your prompt reply, I couldn't see the wood for the trees!
    Sunday, January 12, 2014 7:04 PM