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 です。
- 属性
例
水平方向の を作成するには、水平方向ListBoxStackPanelを指定するテンプレートを作成し、 プロパティとしてItemsPanel設定します。 次の例は、水平 ListBoxをListBoxStyle作成する を示しています。
<Style TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
次の例では、 を ControlTemplate 使用して、角を丸めた水平 ListBox を作成します。 この例では、前の例のように プロパティをItemsPanel設定する代わりに、 内ControlTemplateで horizontal StackPanel を指定します。 プロパティは 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>
または、次の操作を実行して、同じ結果を得ることもできます。 この場合、 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 、視覚的なカスタマイズに優れた柔軟性を提供し、多くのスタイル設定とテンプレートプロパティを提供します。 プロパティまたは プロパティをItemContainerStyleItemContainerStyleSelector使用して、データ項目を含む要素の外観に影響を与えるスタイルを設定します。 たとえば、 の場合 ListBox、生成されたコンテナーは ListBoxItem コントロールです。の場合 ComboBoxはコントロールです ComboBoxItem 。 コントロールでグループ化を使用している場合は、 または GroupStyleSelector プロパティをGroupStyle使用できます。 データ オブジェクトの視覚化を指定するには、 または プロパティをItemTemplateSelector使用ItemTemplateします。 詳細については、「 データ テンプレートの概要」を参照してください。
依存プロパティ情報
識別子フィールド | ItemsPanelProperty |
に設定されたメタデータ プロパティ true |
なし |
適用対象
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示