ItemsPanelTemplate 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定 ItemsPresenter 為 ItemsControl 之項目的版面配置所建立的面板。
public ref class ItemsPanelTemplate : System::Windows::FrameworkTemplate
public class ItemsPanelTemplate : System.Windows.FrameworkTemplate
type ItemsPanelTemplate = class
inherit FrameworkTemplate
Public Class ItemsPanelTemplate
Inherits FrameworkTemplate
- 繼承
範例
若要建立水準 ListBox ,您可以建立範本來指定水準 StackPanel ,並將其設定為 ItemsPanel 屬性。 下列範例顯示建立 ListBoxStyle 水準 ListBox 的 。
<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 內指定水準 StackPanel 。 請注意, 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>
如需如何在 上使用不同樣式和範本化屬性的 ItemsControl 範例,請參閱 資料範本化概觀。
備註
ItemsPanelTemplate會指定用於專案配置的面板。 GroupStylePanel具有 類型 ItemsPanelTemplate 為 的屬性。 ItemsControl 類型具有 ItemsPanel 屬於 類型的 ItemsPanelTemplate 屬性。
每個 ItemsControl 類型都有預設 ItemsPanelTemplate 。 針對 類別 ItemsControl ,預設值 ItemsPanel 是 ItemsPanelTemplate 指定 的 StackPanel 。 ListBox針對 ,預設值會使用 VirtualizingStackPanel 。 針對 MenuItem ,預設值會使用 WrapPanel 。 針對 StatusBar ,預設值會使用 DockPanel 。
建構函式
ItemsPanelTemplate() |
初始化 ItemsPanelTemplate 類別的執行個體。 |
ItemsPanelTemplate(FrameworkElementFactory) |
使用指定的樣板來初始化 ItemsPanelTemplate 類別的執行個體。 |
屬性
Dispatcher |
取得與這個 Dispatcher 關聯的 DispatcherObject。 (繼承來源 DispatcherObject) |
HasContent |
取得值,指出這個樣板是否有最佳化內容。 (繼承來源 FrameworkTemplate) |
IsSealed |
取得值,這個值表示這個物件是否處於不變的狀態,以便無法對其進行變更。 (繼承來源 FrameworkTemplate) |
Resources |
取得或設定可在這個樣板的範圍內使用的資源集合。 (繼承來源 FrameworkTemplate) |
Template |
當樣板為已定義或由寫入器套用時,取得或設定記錄或播放該樣板之 XAML 節點的物件之參考。 (繼承來源 FrameworkTemplate) |
VisualTree |
取得或設定樣板的根節點。 (繼承來源 FrameworkTemplate) |
方法
明確介面實作
INameScope.FindName(String) |
傳回具有所提供之識別名稱的物件。 (繼承來源 FrameworkTemplate) |
IQueryAmbient.IsAmbientPropertyAvailable(String) |
查詢指定的環境屬性 (Ambient Property) 是否可用於目前的範圍。 (繼承來源 FrameworkTemplate) |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應