gpt4 book ai didi

c# - 在WPF中设置listview ItemContainerStyle

转载 作者:行者123 更新时间:2023-11-30 21:40:03 27 4
gpt4 key购买 nike

我有一个 ListView,其中行交替颜色:

<Grid>
<Grid.Resources>
<Style x:Key="RowColorStyle" TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>

<ListView ItemContainerStyle="{StaticResource alternatingStyle}" AlternationCount="2">
</ListView>

</Grid>

现在我已将 listview ItemContainerStyle 设置如下:

<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="lvi_MouseDown" />
<EventSetter Event="PreviewMouseMove" Handler="lvi_MouseMove" />
</Style>
</ListView.ItemContainerStyle>

现在的问题是 listview 多次定义 ItemContainerStyle 主体,因此我尝试在最后定义的 内移动 ItemContainerStyle="{StaticResourcealternateStyle}" >ItemContainerStyle 部分刚刚实现,但我不知道该怎么做。

最佳答案

我不确定您在问什么,但您可以使用 BasedOn 属性将 Style 建立在另一个样式的基础上:

<ListView AlternationCount="2">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource alternatingStyle}">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="lvi_MouseDown" />
<EventSetter Event="PreviewMouseMove" Handler="lvi_MouseMove" />
</Style>
</ListView.ItemContainerStyle>
</ListView>

关于c# - 在WPF中设置listview ItemContainerStyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888051/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com