我正在使用VS 2012中的XAML/WPF。我承认我还不太理解模板和样式。
现在我想将这种样式应用到我的列表视图中,但我无法弄清楚在哪里应用这种样式,即在哪里放置设置样式的代码。为了保持简洁,我省略了很多属性。
我在我的application.xaml文件中定义了一个样式,像这样:
<Style x:Key="ContactGroups" TargetType="ListViewItem">
<!-- Styling omitted here -->
</Style>
现在我想将这种样式应用到我的列表视图中,但我无法弄清楚在哪里应用这种样式,即在哪里放置设置样式的代码。为了保持简洁,我省略了很多属性。
<ListView ItemsSource="{Binding Groups}" SelectedItem="{Binding Path=SelectedGroup, Mode=OneWayToSource}" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="140" Height="25">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Label Content="{Binding Name}" ToolTip="{Binding Name}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>