In this tutorial, you will learn how to show a non-annoying popup layer within a Silverlight web page.

Let's follow these steps:

Step 1

Add a button to your xaml page as shown below:

<Grid x:Name="LayoutRoot" Background="White" >
<Button Width="100" Height="50" x:Name="showPopup"
Click="showPopup_Click" Content="Show Popup" />
</Grid>

Step 2

Then, add the following code to your code behind file (page.xaml.cs):

Popup p = new Popup();
private void showPopup_Click(object sender, RoutedEventArgs e)
{

1. Create a panel control to host other controls
    StackPanel panel1 = new StackPanel();
    panel1.Background = new SolidColorBrush(Colors.Gray);

2. Create a button
    Button button1 = new Button();
    button1.Content = "Close";
    button1.Margin = new Thickness(5.0);
    button1.Click += new RoutedEventHandler(button1_Click);

3. Create a text label
    TextBlock textblock1 = new TextBlock();
    Textblock1.Text = "The popup control";
    Textblock1.Margin = new Thickness(5.0);

4. Add text label and button to the panel
    panel1.Children.Add(textblock1);
    panel1.Children.Add(button1);

Step 3

Now, make the panel a child of the popup so that the panel will be shown within the Popup when displayed:

   p.Child = panel1;

And you can set a position:

 p.VerticalOffset = 25;
   p.HorizontalOffset = 25;

Use this code to show the popup:

p.IsOpen = true;
}

void button1_Click(object sender, RoutedEventArgs e)
{

Then, to close the popup, follow this code:

// Close the popup.
   p.IsOpen = false;
}

Step 4

Now run the application. You can see the page with a button. When you click on the button, a popup layer will appear with a text label and a button in it. When you click on the button in the popup, it will close the popup.

HostForLIFE.eu Silverlight 6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.