MSDN Library
信息
您所需的主题如下所示。但此主题未包含在此库中。

Popup.Child 属性

2013/12/13

获取或设置要在弹出项中承载的内容。

Namespace:  System.Windows.Controls.Primitives
程序集:  System.Windows(位于 System.Windows.dll 中)
XMLNS for XAML: 未映射到 xmlns。

声明
Public Property Child As UIElement
<Popup ...>
  singleChild
</Popup>

XAML 值

singleChild

一个对象元素,弹出项会将它显示为内容。该子元素必须是从 UIElement 派生的对象。

属性值

类型: System.Windows.UIElement
要在弹出项中承载的内容。

依赖项属性标识符字段: ChildProperty

Child 属性可以是任何单个 UIElement。为了承载多个项,需要创建一个 UserControl,或者在诸如 StackPanelGrid 这样的容器中承载内容。弹出项将始终显示在现有内容(包括其他弹出控件)之上。

ChildPopup 的 XAML 内容属性,因此您不需要在 XAML 语法中指定 Popup.Child 属性元素。有关 XAML 内容属性语法的更多信息,请参见 XAML for Windows Phone

下面的示例演示如何使用 Popup 显示包含一个文本块和一个按钮的边框。为了简明起见,弹出项内容是通过内联方式创建的,但通常您会在单独的用户控件中创建此内容,并使用该控件的实例作为弹出项的子级。


' Create the popup object. 
Private p As New Popup()
Private Sub showPopup_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Create some content to show in the popup. Typically you would 
    ' create a user control. 
    Dim border As New Border()
    border.BorderBrush = New SolidColorBrush(Colors.Black)
    border.BorderThickness = New Thickness(5)

    Dim panel1 As New StackPanel()
    panel1.Background = New SolidColorBrush(Colors.LightGray)

    Dim button1 As New Button()
    button1.Content = "Close"
    button1.Margin = New Thickness(5)
    AddHandler button1.Click, AddressOf button1_Click
    Dim textblock1 As New TextBlock()
    textblock1.Text = "The popup control"
    textblock1.Margin = New Thickness(5)
    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 = 150
    p.HorizontalOffset = 150

    ' Open the popup. 
    p.IsOpen = True

End Sub

Private Sub button1_Click(ByVal sender As Object, _
    ByVal e As RoutedEventArgs)
    ' Close the popup. 
    p.IsOpen = False

End Sub



<phone:PhoneApplicationPage x:Class="Popup2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    FontFamily="Trebuchet MS" FontSize="11" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="800" d:DesignWidth="480">

        <StackPanel x:Name="LayoutRoot" Background="Transparent">
            <Button x:Name="showPopup" 
            Click="showPopup_Click" Content="Show Popup" />
        </StackPanel>
</phone:PhoneApplicationPage>


Windows Phone OS

受以下版本支持: 8.0, 7.1, 7.0

Windows Phone

显示:
© 2016 Microsoft