wpf 如何设置 ListView 项目的样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4474436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I Style ListView Items?
提问by Jeff LaFay
I have a ListView
that is data bound and I want to alter the font properties for each item. I'm not having much luck finding the appropriate properties. The ListView
is pretty simple so I don't expect it to be too difficult to change, I'm just not finding what I'm wanting as of yet.
我有一个ListView
数据绑定,我想更改每个项目的字体属性。我没有太多运气找到合适的属性。这ListView
很简单,所以我不认为它很难改变,我只是还没有找到我想要的东西。
<ListView ItemsSource="{Binding Updates}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding TimeStamp}" Header="TimeStamp" />
<GridViewColumn DisplayMemberBinding="{Binding UpdateData}" />
</GridView>
</ListView.View>
</ListView>
回答by Thomas Levesque
You can set the ItemContainerStyle
:
您可以设置ItemContainerStyle
:
<ListView ItemsSource="{Binding Updates}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding TimeStamp}" Header="TimeStamp" />
<GridViewColumn DisplayMemberBinding="{Binding UpdateData}" />
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="Blue" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontStyle" Value="Italic" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
Note that it will apply to the itemsof the ListView
, not the ListView
itself (e.g. the column headers won't be affected). If you want to apply those properties to the whole ListView
, you can set them directly on the ListView:
请注意,它将应用于 的项目,而ListView
不是其ListView
本身(例如,列标题不会受到影响)。如果要将这些属性应用于整个ListView
,可以直接在 ListView 上设置它们:
<ListView ItemsSource="{Binding Updates}"
Foreground="Blue" FontSize="14" ...>