How to create modal popup in silverlight ?

In Silverlight 2.0, creating modal popup was some tedious work. But in Silverlight 3.0,4.0,5.0, we can create very easily like this.

Step1: Create the new silverlight project

step2:Right clik on Solution Exp of silverlight project and add one Silverlight Child Window like this Img

Step3: Keep one Img in ChildWindow.xaml page like this

<controls:ChildWindow x:Class=”ChildWindow.ChildWindow2″




Width=”400″ Height=”300″


<Grid x:Name=”LayoutRoot” Margin=”2″>


<RowDefinition />

<RowDefinition Height=”Auto” />



<Image x:Name=”img” />

<TextBlock x:Name=”caption” TextWrapping=”Wrap” />


<Button x:Name=”CancelButton” Content=”Cancel” Click=”CancelButton_Click” Width=”75″ Height=”23″ HorizontalAlignment=”Right” Margin=”0,12,0,0″ Grid.Row=”1″ />

<Button x:Name=”OKButton” Content=”OK” Click=”OKButton_Click” Width=”75″ Height=”23″ HorizontalAlignment=”Right” Margin=”0,12,79,0″ Grid.Row=”1″ />



Step4:Create one button in main page like this


<Button x:Name=”Button1″ Content=”Click Here” Click=”Button1_Click” Height=”28″ Width=”180″></Button>


Step5: Create the code in code behind page mainpage.xaml.cs like this

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Navigation;

using System.Windows.Media.Imaging;

namespace ChildWindow


public partial class Test1 : Page


public Test1()




private void Button1_Click(object sender, RoutedEventArgs e)


ChildWindow2 win = new ChildWindow2();

win.img.Source = new BitmapImage(new Uri(“Img/Winter.jpg”, UriKind.Relative));

win.Title = “Silverlight popup”;






2 thoughts on “How to create modal popup in silverlight ?

  1. chamara February 25, 2012 / 6:58 am

    I’m using silverlight with have added silverlight content to master page using following code

    in the silverlight MainPage.xaml i have a button and when click on the button it opens a ChildWindow.

    private void btnView_Click(object sender, RoutedEventArgs e)
    PopUpWindow PPW = new PopUpWindow();
    PPW.chart1.DataContext = App.Current.Resources[“ChartResult”];

    issue is the child window shows only in masterpage,its not covering the whole screen with the master page and the content can i make it to show the childWindow on ful screen

  2. andrewgrothe April 16, 2013 / 8:46 pm

    simply put and works great. love the built in open/close animations.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.