删除列表框项目虚线边框

Kia*_*eng 1 c# wpf custom-controls wpf-controls

我有一个定制风格ListBoxItemBorder周围的ContentPresenter.(代码见下文).我的边框充当我的选择指示器,当您选择它时会变为灰色.当我使用鼠标时一切都很好,但是当我使用键盘时,会出现一个丑陋的虚线灰色边框.我该如何删除它?

图片:

UGLY GRAY BORDER

您可以看到,当我鼠标悬停/单击时ListBoxItem,包含背景的边框环绕该项目.但是当我使用键盘时,会出现一个丑陋的虚线边框.

码:

<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"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
Run Code Online (Sandbox Code Playgroud)

The*_*iot 5

这个答案由薏苡仁,喜悦

<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> 
   <Setter Property="FocusVisualStyle" Value="{x:Null}"/> ....
Run Code Online (Sandbox Code Playgroud)