Popup.Child Property
Gets or sets the content to be hosted in the popup.
Namespace: System.Windows.Controls.Primitives
Assembly: System.Windows (in System.Windows.dll)
Dependency property identifier field: ChildProperty
The Child property can be any single UIElement. In order to host multiple items, create a UserControl or host the content in a container, such as StackPanel or Grid. A popup will always appear on top of existing content, including other popup controls.
Child is the XAML content property for Popup, so you do not need to specify a Popup.Child property element in the XAML syntax. For more information about XAML content property syntax, see XAML Overview.
The following example shows how to use a Popup to display a border that contains a text block and a button. The popup content is created inline for conciseness, but you would typically create this content in a separate user control and use an instance of that control as the child of the popup.
// Create the popup object. Popup p = new Popup(); private void showPopup_Click(object sender, RoutedEventArgs e) { // Create some content to show in the popup. Typically you would // create a user control. Border border = new Border(); border.BorderBrush = new SolidColorBrush(Colors.Black); border.BorderThickness = new Thickness(5.0); StackPanel panel1 = new StackPanel(); panel1.Background = new SolidColorBrush(Colors.LightGray); Button button1 = new Button(); button1.Content = "Close"; button1.Margin = new Thickness(5.0); button1.Click += new RoutedEventHandler(button1_Click); TextBlock textblock1 = new TextBlock(); textblock1.Text = "The popup control"; textblock1.Margin = new Thickness(5.0); panel1.Children.Add(textblock1); panel1.Children.Add(button1); border.Child = panel1; // Set the Child property of Popup to the border // which contains a stackpanel, textblock and button. p.Child = border; // Set where the popup will show up on the screen. p.VerticalOffset = 25; p.HorizontalOffset = 25; // Open the popup. p.IsOpen = true; } void button1_Click(object sender, RoutedEventArgs e) { // Close the popup. p.IsOpen = false; }
<UserControl x:Class="Popup2.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="Trebuchet MS" FontSize="11" Width="200" Height="200"> <StackPanel x:Name="LayoutRoot" Background="White"> <Button Width="100" Height="50" x:Name="showPopup" Click="showPopup_Click" Content="Show Popup" /> </StackPanel> </UserControl>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.