ItemsControl.ItemsPanel プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
項目のレイアウトを制御するパネルを定義するテンプレートを取得または設定します。
public:
property System::Windows::Controls::ItemsPanelTemplate ^ ItemsPanel { System::Windows::Controls::ItemsPanelTemplate ^ get(); void set(System::Windows::Controls::ItemsPanelTemplate ^ value); };
[System.ComponentModel.Bindable(false)]
public System.Windows.Controls.ItemsPanelTemplate ItemsPanel { get; set; }
[<System.ComponentModel.Bindable(false)>]
member this.ItemsPanel : System.Windows.Controls.ItemsPanelTemplate with get, set
Public Property ItemsPanel As ItemsPanelTemplate
プロパティ値
項目のレイアウトに使用するパネルを定義する ItemsPanelTemplate。 ItemsControl の既定値は、StackPanel を指定する ItemsPanelTemplate です。
- 属性
例
水平方向を作成するには、水平方向 ListBoxを指定 StackPanel し、プロパティとして設定するテンプレートを ItemsPanel 作成できます。 次の例は、水平ListBoxをListBoxStyle作成する例を示しています。
<Style TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
次の例では、角が丸い水平ListBoxを作成するために a ControlTemplate を使用します。 この例では、前の例のようにプロパティを ItemsPanel 設定する代わりに、 StackPanel ControlTemplate. このIsItemsHostプロパティは、生成された項目がパネルに表示されることを示す 、上StackPanelに設定true
されます。 この方法で指定すると、コントロールの 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>
または、次の操作を実行して、同じ結果を得ることもできます。 この場合、 ItemsPresenter 項目のレイアウト用のパネルが作成されます ItemsPanelTemplate。
<Style TargetType="{x:Type ListBox}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border CornerRadius="5"
Background="{TemplateBinding ListBox.Background}">
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
注釈
の場合、 ListBox既定値 ItemsPanelTemplate は を指定します VirtualizingStackPanel。 の場合 MenuItem、既定で使用 WrapPanelされます。 の場合 StatusBar、既定で使用 DockPanelされます。
内の項目 ItemsControlのレイアウトに影響を与えるために、このプロパティを使用して、 ItemsPanelTemplate.
ビジュアル ItemsControl のカスタマイズに優れた柔軟性を提供し、多くのスタイル設定とテンプレートのプロパティを提供します。 プロパティまたはプロパティを ItemContainerStyle 使用して、データ項目を ItemContainerStyleSelector 含む要素の外観に影響を与えるスタイルを設定します。 たとえば、 ListBox生成されたコンテナーはコントロールです ListBoxItem 。たとえば ComboBox、コントロールです ComboBoxItem 。 コントロールでグループ化を使用している場合は、or GroupStyleSelector プロパティをGroupStyle使用できます。 データ オブジェクトの視覚化を指定するには、またはプロパティをItemTemplateSelector使用ItemTemplateします。 詳細については、「 データ テンプレートの概要」を参照してください。
依存プロパティ情報
識別子フィールド | ItemsPanelProperty |
に設定されたメタデータ プロパティ true |
なし |