Home > .NET, Silverlight > Silverlight: Create Popup Dialog using ChildWindow Class

Silverlight: Create Popup Dialog using ChildWindow Class

This post is a walkthrough to create a login screen popup dialog using the ChildWindow Class

  • Right click your solution or folder
  • Add a new item
  • Select Silverlight from the right list of the Add New Item dialog


  • Add a Silverlight Child Window


  • Add couple of labels, a Textbox and a Password box


In this scenario, I have the username and password hardcoded in the code. Ideally, you validate the username and password via a service

  • Add the following code to the OK and Cancel Click event handlers
private void OKButton_Click(object sender, RoutedEventArgs e)
   if (textBox1.Text == "Username" && textBox2.Password == "Password")
      this.DialogResult = true;
      MessageBox.Show("Incorrect username and/or password", "Error", MessageBoxButton.OK);

private void CancelButton_Click(object sender, RoutedEventArgs e)
   this.DialogResult = false;

In code, I had a login button on the MainView.

private void btnAdmin_Click(object sender, RoutedEventArgs e)
   var dialog = new LoginDlg();
   dialog.Closed += new EventHandler(dialog_Closed);
void dialog_Closed(object sender, EventArgs e)
   var dialog = (LoginDlg)sender;
   if (dialog.DialogResult == true)
   dialog.Closed -= new EventHandler(dialog_Closed);

Notice that the Show method doesn’t return a value. I have to listen/subscribe/handle the closed event.

Categories: .NET, Silverlight Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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

%d bloggers like this: