在我当前正在处理的控件中,当某个项目被聚焦时,默认的焦点矩形框跨越整行和所有可见的子项目。我知道如何隐藏它,但是当该项目有键盘焦点时,仍然需要这样的焦点指示器。我已经阅读了IsKeyboardFocused属性,但是当用鼠标单击该项时,它也会为真。所以我想我需要以某种方式使用FocusVisualStyle。但我无法弄清楚如何使用。
以下是默认焦点的外观:
以下是它应该显示的内容:
以下是控件模板的XAML代码:
以下是默认焦点的外观:
![enter image description here](https://istack.dev59.com/YwWAJ.webp)
![enter image description here](https://istack.dev59.com/uALz5.webp)
<Border ...>
<ContentPresenter FocusManager.IsFocusScope="True"
Content="{TemplateBinding HeaderedContentControl.Header}"
ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"
ContentSource="Header"
Name="PART_Header" .../>
</Border>
<!-- Additional border glare inside the item -->
<Border BorderThickness="1" BorderBrush="#80ffffff" Margin="1"
SnapsToDevicePixels="True" CornerRadius="2"/>
<!-- Focus rectangle inside the item -->
<Rectangle StrokeDashArray="1 2" StrokeThickness="1" Stroke="Black"
SnapsToDevicePixels="True" Margin="2"
Visibility="Hidden" Name="FocusRectangle"
FocusVisualStyle="{StaticResource FocusStyle}"/>
我的XAML中已经有一个默认情况下不可见的焦点矩形。通过FocusVisualStyle或其他方式,它应该变得可见。但是我没有成功做到这一点。要么在任何焦点下都可见,要么从未出现过。