Словарь ресурсов
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ItemsPanelTemplate x:Key="lstViewItemsPanelTemplate">
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
<Style TargetType="ListViewItem" x:Key="lstViewItemContainerStyle">
<Setter Property="HorizontalContentAlignment"
Value="Stretch"/>
</Style>
<DataTemplate x:Key="lstViewItemTemplate">
<Grid Width="100"
Height="100"
Background="{Binding Color}">
<StackPanel Margin="10">
<TextBlock Text="{Binding Title}"/>
<TextBlock Text="{Binding Description}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ResourceDictionary>
Список представлений
<ListView ItemsPanel="{StaticResource lstViewItemsPanelTemplate}"
ItemContainerStyle="{StaticResource lstViewItemContainerStyle}"
ItemTemplate="{StaticResource lstViewItemTemplate}"/>
или
Вы также можете определить глобальный Style
в ResourceDictionary.xaml
, например,
<Style TargetType="ListView">
<Setter Property="ItemsPanel" Value="{StaticResource lstViewItemsPanelTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource lstViewItemContainerStyle}"/>
<Setter Property="ItemTemplate" Value="{StaticResource lstViewItemTemplate}"/>
</Style>