【发布时间】:2010-12-02 10:13:35
【问题描述】:
我有一个自定义样式的 ListBoxItem,Border 围绕着 ContentPresenter。 (代码如下)。我的边框充当我的选择指示器,并在您选择它时变为灰色。当我使用鼠标时一切都很好,但是当我使用键盘的那一刻,一个难看的灰色虚线边框就出来了。如何删除它?
图片:
您可以看到,当我将鼠标悬停/单击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>
【问题讨论】:
标签: c# wpf wpf-controls custom-controls