删除列表框项目虚线边框

时间:2010-12-02 10:13:36

标签: c# wpf wpf-controls custom-controls

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

照片管理:

UGLY GREY 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>

1 个答案:

答案 0 :(得分:5)

this来自jobi-joy

<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> 
   <Setter Property="FocusVisualStyle" Value="{x:Null}"/> ....
相关问题