WPF为ItemsControl设置ItemsPanelTemplate
1. 直接在XAML中以对象属性的方式
1 <ItemsControl x:Name="lstNew"> 2 <ItemsControl.ItemsPanel> 3 <ItemsPanelTemplate> 4 <StackPanel VerticalAlignment="Top" Orientation="Vertical"> 5 <StackPanel.LayoutTransform> 6 <ScaleTransform ScaleX="1" ScaleY="-1" /> 7 </StackPanel.LayoutTransform> 8 </StackPanel> 9 </ItemsPanelTemplate> 10 </ItemsControl.ItemsPanel> 11 </ItemsControl>
2. 以资源的方式来设置
2.1.在资源文件中定义好ItemsPanelTemplate
1 <ItemsPanelTemplate x:Key="ItemsPanelTemplate"> 2 <StackPanel VerticalAlignment="Top" Orientation="Vertical"> 3 <StackPanel.LayoutTransform> 4 <ScaleTransform ScaleX="1" ScaleY="-1" /> 5 </StackPanel.LayoutTransform> 6 </StackPanel> 7 </ItemsPanelTemplate>
2.2.在XAML中访问资源
1 <ItemsControl ItemsPanel="{DynamicResource ItemsPanelTemplate}"></ItemsControl>
注意:以资源的方式设置,其实是设置ItemsPanel的ItemsPanelTemplate