User Controls and the Popup Dialog

There are instances when it is desirable to set the content of a dialog control to a custom User Control, in the example below we show how to first create a custom user control and secondly to set it as the content source for a popup dialog:

Creating the User Control

The XAML here creates a simple login form consisting of username and password fields.

<UserControl x:Class="DialogUserControl.myUserControl"
    Width="300" Height="50">
    <Grid x:Name="LayoutRoot">
            <RowDefinition Height="25" />
            <RowDefinition Height="25" />
            <ColumnDefinition Width="70" />
            <ColumnDefinition />
        <TextBlock Grid.Row="0" Grid.Column="0" Text="Username:" HorizontalAlignment="Right" VerticalAlignment="Center" />
        <TextBox Grid.Row="0" Grid.Column="1" Width="150" Height="20" HorizontalAlignment="Left" VerticalAlignment="Center" />
        <TextBlock Grid.Row="1" Grid.Column="0" Text="Password:" HorizontalAlignment="Right" VerticalAlignment="Center" />
        <PasswordBox Grid.Row="1" Grid.Column="1" Width="150" Height="20" HorizontalAlignment="Left" VerticalAlignment="Center" />

As this is a very simple example there is no C# to write, your application will of course be more complex.  So next we have the main control that contains the Popup Dialog which has it's content set to the custom user control we created earlier:

<UserControl x:Class="DialogUserControl.Page"
    Width="500" Height="500">
    <Canvas x:Name="LayoutRoot" Background="White" Width="500" Height="500">
        <liquid:Dialog x:Name="popup" Width="230" Height="110" Buttons="OK,Cancel" Title="Login" IsOpen="True" IsResizable="False" IsMaximizeEnabled="False" IsMinimizeEnabled="False">
            <my:myUserControl />

The important line above is xmlns:my="clr-namespace:DialogUserControl", this allows you to refer to the custom User Control anywhere in your XAML.

Example User Control in a Popup Dialog:

A User Control in a Popup Dialog

Latest Games
Zombie Escape
Apr 19, 2016
Plays: 2,438

Zombie Escape ScreenshotDrive fast before the crazy mutant zombies get you!

6 Ratings/4.1 Average
Car Parking
Jan 16, 2016
Plays: 2,316

Car Parking ScreenshotGuide the car to its parking space in this fun Car Parking game.

1 Rating/5 Average
Trash It
Jan 11, 2016
Plays: 2,220

Trash It ScreenshotAim for the Trash Can and get the various items of Trash in the bin.

4 Ratings/5 Average
Sky Fly
Jan 11, 2016
Plays: 2,347

Sky Fly ScreenshotFly your plane in this colorful vertical scrolling shoot-em-up. Blast the bad guys and collect any bonus's they leave behind.

1 Rating/5 Average
Professor Snappy
Jan 11, 2016
Plays: 1,911

Professor Snappy ScreenshotPop as many bubbles as possible in this fun and colorful bubble popping game. The levels start off easy enough but gradually get harder!

1 Rating/5 Average
Monster Match Saga
Jan 10, 2016
Plays: 2,237

Monster Match Saga ScreenshotHere we have a bunch of monsters that need to be matched up. Look out for the bomb and spinning monsters that will cause special damage!

3 Ratings/4.6 Average
Fly Bird Fly
Jan 10, 2016
Plays: 2,046

Fly Bird Fly ScreenshotGuide your friendly Bird through the maze of pipes and other obstacles collecting the Stars in this cool arcade game inspired by the legendary Flappy Bird.

1 Rating/5 Average
Life In One
Jan 10, 2016
Plays: 2,205

Life In One ScreenshotYou are stranded on an Alien planet. Your goal is to build a space rocket and escape. Start by building units to create power and mine the metal patches. Build defenses to defend your base from the advancing Aliens and Zombies!

2 Ratings/3 Average
X Pool
Jan 02, 2016
Plays: 2,849

X Pool ScreenshotPlay Pool against the computer or battle against your friends in the online mode!

3 Ratings/3 Average
Fruit Slicer
Jan 02, 2016
Plays: 1,954

Fruit Slicer ScreenshotSlice the fruit that is thrown up onto the screen. Slice the fruit into multiple pieces for maximum points!

1 Rating/5 Average