Tom*_*sup 3 c# wpf xaml listview
我有一个带有Horizontal WrapPanel的ListView作为其ItemsPanelTemplate.我想摆脱所选项目的蓝色背景.它仅在所选项目的左侧可见.
在SO上有许多类似的问题,我尝试了很多解决方案,但没有一个有效.
这是我已经尝试过的:
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Resources>
<!-- Foreground for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black"/>
<!-- Background for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent"/>
<!--SelectedItem without focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
</Style.Resources>
</Style>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="Control.MouseDoubleClick" Handler="HandleSelectedItemDoubleClick"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="2" ScaleY="2" CenterX="12" CenterY="12" />
</Setter.Value>
</Setter>
<Setter Property="Panel.ZIndex" Value="150"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="BorderBrush" Value="{x:Null}" />
<Setter Property="Background" Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Width="210" Margin="15" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)
你需要覆盖SystemColors.HighlightBrushKey的ListView是Transparent(或任何你想要的颜色)
我通常把ListView.Resources它放在这里,所以它只适用于特定的ListView,而不是全部ListViews在我的应用程序中
<ListView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent"/>
</ListView.Resources>
Run Code Online (Sandbox Code Playgroud)
它已经非常接近你的代码了,但你需要设置它ListView.Resources,而不是ListViewItem.Resources
| 归档时间: |
|
| 查看次数: |
6125 次 |
| 最近记录: |