I have a custom styled ListBoxItem
with a Border
surrounding a ContentPresenter
. (Code found below). My border acts as my selection indicator and turns grey when you select it. All is fine when I use the mouse, but the moment I use my keyboard, an ugly dotted grey border comes out. How do I remove it?
Pics:
You can see that when I mouse over/click on the ListBoxItem
, a border with included background surrounds the item. But an ugly dotted border pops out when I use the keyboard.
Code:
<Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<StackPanel>
<Border Name="HighlightBorder"
Padding="30"
BorderBrush="Transparent"
BorderThickness="1"
CornerRadius="5"
>
<ContentPresenter/>
</Border>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="HighlightBorder" Property="Background" Value="#F3F3F3"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="HighlightBorder" Property="Background" Value="#DFDFDF"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="HighlightBorder" Property="Background" Value="#DFDFDF"/>
</Trig开发者_StackOverflow社区ger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
From this answer by jobi-joy
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/> ....
精彩评论