我正在使用VS 2012中的XAML/WPF。我承认我不太了解模板和样式。将样式从资源应用到ListView.ItemContainerStyle
我已经在我的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>
运行和编译没有错误,但我的风格没有得到应用。我真的很困惑,如何可能。当获取正在使用的颜色的十六进制并在我的XAML(或整个应用程序)中搜索它们时,颜色不会出现在任何地方。我怀疑你的回答是正确的,我还有其他问题。 – HK1
是的,你发布的问题。这是你实现它的方式。不知道你的其他问题。 –
考虑打开另一个问题,其中包含您的风格的详细信息,以便可以让更多人查看。 –