Adding a Popup to a Silverlight application is as easy as dragging and dropping a Popup control from the ToolBox
<Popup x:Name="popup" />
However if you want to programmatically add content to the Popup control, here’s how to do so:
private void Button_Click(object sender, RoutedEventArgs e)
{
//Create Popup content with a border, background color
// and a child element Button
popup.Child = new Border()
{
Height= 150,
Width=150,
Background = new SolidColorBrush(Colors.LightGray),
Child = new Button() { Content = "OK", Height=50, Width=50 }
};
// Show/hide Popup
popup.IsOpen = !popup.IsOpen;
}
}
As you can see, we are programmatically adding a Border element, specifying attributes of the Popup like Height, Width, Background Color and also adding a Button inside the popup, with attributes of its own. It’s common for developers to use the Popup type to create Cascading Menus programmatically!
Tweet
No comments:
Post a Comment