InlineUIContainer.Child 屬性

定義

取得或設定 UIElement 裝載的 InlineUIContainer

public:
 property System::Windows::UIElement ^ Child { System::Windows::UIElement ^ get(); void set(System::Windows::UIElement ^ value); };
public System.Windows.UIElement Child { get; set; }
member this.Child : System.Windows.UIElement with get, set
Public Property Child As UIElement

屬性值

UIElement

UIElement 裝載的 InlineUIContainer

範例

下列範例示範如何使用 InlineUIContainer 元素來裝載 UIElement 流程內容內的元素。

<FlowDocument ColumnWidth="400">
  <Paragraph Background="GhostWhite">
    <Run>
      A UIElement element may be embedded directly in flow content
      by enclosing it in an InlineUIContainer element.
    </Run>
    <LineBreak/>
    <LineBreak/>
    <InlineUIContainer>
      <Button>Click me!</Button>
    </InlineUIContainer>
    <LineBreak/>
    <LineBreak/>
    <Run>
      The InlineUIContainer element may host no more than one top-level
      UIElement.  However, other UIElements may be nested within the
      UIElement contained by an InlineUIContainer element.  For example,
      a StackPanel can be used to host multiple UIElement elements within
      an InlineUIContainer element.
    </Run>
    <InlineUIContainer>
      <StackPanel>
        <Label Foreground="Blue">Choose a value:</Label>
        <ComboBox>
          <ComboBoxItem IsSelected="True">a</ComboBoxItem>
          <ComboBoxItem>b</ComboBoxItem>
          <ComboBoxItem>c</ComboBoxItem>
        </ComboBox>
        <Label Foreground ="Red">Choose a value:</Label>
        <StackPanel>
          <RadioButton>x</RadioButton>
          <RadioButton>y</RadioButton>
          <RadioButton>z</RadioButton>
        </StackPanel>
        <Label>Enter a value:</Label>
        <TextBox>
          A text editor embedded in flow content.
        </TextBox>
      </StackPanel>
    </InlineUIContainer>
  </Paragraph>
</FlowDocument>

下圖顯示此範例的轉譯方式。

螢幕擷取畫面:內嵌於非固定格式內容中的 UIElement 項目

下列範例示範如何以程式設計方式使用 Child 屬性。

Paragraph parx = new Paragraph();
Run run1 = new Run(" Text to precede the button... ");
Run run2 = new Run(" Text to follow the button... ");

// Create a new button to be hosted in the paragraph.
Button buttonx = new Button();
buttonx.Content = "Click me!";

// Create a new InlineUIContainer, and assign the button 
// as the UI container's child.
InlineUIContainer uiCont = new InlineUIContainer();
uiCont.Child = buttonx;

// Add the text runs and UI container to the paragraph, in order.
parx.Inlines.Add(run1);
parx.Inlines.Add(uiCont);
parx.Inlines.Add(run2);
Dim parx As New Paragraph()
Dim run1 As New Run(" Text to precede the button... ")
Dim run2 As New Run(" Text to follow the button... ")

' Create a new button to be hosted in the paragraph.
Dim buttonx As New Button()
buttonx.Content = "Click me!"

' Create a new InlineUIContainer, and assign the button 
' as the UI container's child.
Dim uiCont As New InlineUIContainer()
uiCont.Child = buttonx

' Add the text runs and UI container to the paragraph, in order.
parx.Inlines.Add(run1)
parx.Inlines.Add(uiCont)
parx.Inlines.Add(run2)

備註

InlineUIContainer可以直接裝載一個 UIElement 以上的子系。 不過,所 InlineUIContainer 裝載的子專案可能會裝載自己的子專案。

在 XAML 中,將 UIElement 包裝在 中相當於將 設定 UIElement 為 屬性的值 ChildInlineUIContainer

適用於