Panel.IsItemsHost 屬性

定義

取得或設定值,這個值表示這是 Panel 使用者介面的容器, (UI) 產生的 ItemsControl 專案。

public:
 property bool IsItemsHost { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(false)]
public bool IsItemsHost { get; set; }
[<System.ComponentModel.Bindable(false)>]
member this.IsItemsHost : bool with get, set
Public Property IsItemsHost As Boolean

屬性值

Boolean

如果這個 Panel 執行個體是項目主控件則為 true,否則為 false。 預設值是 false

屬性

範例

下列範例會使用 ControlTemplate 來建立水準 ListBox 。 水準 StackPanel 是在 內 ControlTemplate 指定。 屬性 IsItemsHost 設定 true 為 上的 StackPanel ,表示產生的專案應該放在面板中。 以這種方式指定時, ItemsPanel 控制項的使用者 ControlTemplate 無法使用 取代 。 因此,只有在您知道不想在不使用範本的情況下取代面板時,才執行此動作。

<Style TargetType="ListBox">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ListBox">
        <Border CornerRadius="5" Background="{TemplateBinding ListBox.Background}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel Orientation="Horizontal"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       IsItemsHost="True"/>
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

或者,您可以設定 ItemsControl.ItemsPanel 屬性。 下列範例會在 的 ListBoxStyle 設定 ItemsPanel

<Grid.Resources>
  <Style TargetType="Separator">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Separator}">
          <Border Width="2" Height="12" Margin="4" Background="Gray"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="ListBox">
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Horizontal"
                      VerticalAlignment="Center"
                      HorizontalAlignment="Center"/>
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
  </Style>
  
</Grid.Resources>

備註

您無法將資料系結至此屬性。

相依性屬性資訊

識別碼欄位 IsItemsHostProperty
中繼資料屬性設定為 true IsNotDataBindable

適用於

另請參閱