I'm trying to hide the visual hints that indicate selection in a WPF ListBox
. This answer suggests this should work by overriding the SystemColors
for that ListBox
.
I created a new WPF project and edited the MainWindow.xaml
like this:
<Window x:Class="WpfListboxWithoutSelection.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfListboxWithoutSelection"
xmlns:s="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="150" Width="325">
<Grid>
<ListBox>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</ListBox.Resources>
<s:String>Item 1</s:String>
<s:String>Item 2</s:String>
<s:String>Item 3</s:String>
</ListBox>
</Grid>
</Window>
Unfortunately this doesn't work, the window appears like this:
Any idea what I'm doing wrong? How can I remove the blue colors that appear on the selected item and on the one hovered?