gpt4 book ai didi

WPF 从 GridView 的选择/鼠标上移除光泽效果

转载 作者:行者123 更新时间:2023-12-01 23:40:34 25 4
gpt4 key购买 nike

我搜索了这个简单问题的答案,但还没有找到解决方案。我有以下代码:

<Grid>
<Border BorderBrush="#666666" BorderThickness="1,1,1,1" CornerRadius="3">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF020f1e" Offset="0"/>
<GradientStop Color="#FF484F58" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<ListView Name="lvUsers" Background="Transparent" Foreground="White" Margin="3" FontSize="12" SelectionChanged="lvUsers_SelectionChanged">

<ListView.Template>
<ControlTemplate TargetType="{x:Type ListView}">
<Border CornerRadius="1" BorderThickness="1" BorderBrush="Transparent">
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListView.Template>

<ListView.View>
<GridView>

<GridView.Columns>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding ID}" IsChecked="{Binding IsChecked}" Checked="CheckBox_CheckedChanged" Unchecked="CheckBox_CheckedChanged" IsHitTestVisible="False" Focusable="False"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding ID}" Header="ID" />
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" />
</GridView.Columns>
</GridView>
</ListView.View>

<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />

<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Transparent"/>

</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Black"/>
</Trigger>

</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Border>
</Grid>

当我选择或“鼠标悬停”一行时,会产生以下效果:

MyApplication

我想移除那个光泽效果并获得完全普通“ListView”的样式:

Target Application

您能告诉我实现此目标的最简单方法吗?

非常感谢

最佳答案

ListViewItem 在其模板 (Controltemplate.Triggers) 中有一些奇特的触发器,这些触发器在某些情况下会改变背景(例如,对于选定的项目)。要删除它们,请设置一个没有触发器的简化模板:

<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<GridViewRowPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- your triggers for IsMouseOver and IsSelected -->
</Style.Triggers>

关于WPF 从 GridView 的选择/鼠标上移除光泽效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42200775/

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