Search code examples
uwpuser-controlsvisibility

How to open a User Control in UWP


I can't seem to find a method for the Usercontrol class that allows you to open a user control.

I know if you use windows Forms or WPF, you can use the Usercontrol.show() method, however UWP does not have a Usercontrol.show() method or anything equivalent to that.

I have also tried setting the visibility to visible and that does not work either

Here is the Usercontrol UWP class documentation Usercontrol

Any ideas?


Solution

  • In UWP, you can understand UserControl as a container in which some controls are placed.

    For a control container, the way to display it on the interface is to put it in the visual tree.

    UserControl does not have a Show method. To show it, you can do this:

    <Grid x:Name="RootGrid">
        <MyUserControl .../>
    </Grid>
    

    or add it in code-behind

    RootGrid.Children.Add(new MyUserControl());