wpf ItemsControl 默认样式 & ItemsPanelTemplate 存档,方便手头没有 vs 时查阅.
1 <!-- ItemsControl 的样式 --> 2 <Style x:Key = "ItemsControlStyle1" 3 TargetType = "{x:Type ItemsControl}" > 4 <Setter Property = "Template" > 5 <Setter.Value> 6 <ControlTemplate 7 TargetType = "{x:Type ItemsControl}" > 8 <Border 9 Padding = "{TemplateBinding Padding}" 10 Background = "{TemplateBinding Background}" 11 BorderBrush = "{TemplateBinding BorderBrush}" 12 BorderThickness = "{TemplateBinding BorderThickness}" 13 SnapsToDevicePixels = "true" > 14 <ItemsPresenter 15 SnapsToDevicePixels = "{TemplateBinding SnapsToDevicePixels}" /> 16 </Border> 17 </ControlTemplate> 18 </Setter.Value> 19 </Setter> 20 </Style> 21 22 <!-- ItemsControl 内部布局面板的模版 --> 23 <ItemsPanelTemplate 24 x:Key = "ItemsControlItemsPanel1" > 25 <StackPanel /> 26 </ItemsPanelTemplate> 27 28 <!-- 每一项的数据模版 --> 29 <DataTemplate x:Key = "ItemsControlItemTemplate1" > 30 <Grid /> 31 </DataTemplate> 32 33 <!-- 使用方式 --> 34 <ItemsControl 35 ItemTemplate = "{DynamicResource ItemsControlItemTemplate1}" 36 ItemsPanel = "{DynamicResource ItemsControlItemsPanel1}" 37 Style = "{DynamicResource ItemsControlStyle1}" />