【发布时间】:2023-03-20 20:15:01
【问题描述】:
我有一个带有显示项目列表的 ListBox 的 WPF 应用程序。 每个项目都有 IsChecked 属性。
我已将列表框的 ItemContainerStyle 的样式更改为 follos:
<Style x:Key="OrgListItemStyle" TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ToggleButton IsChecked="{Binding IsChecked}">
<ContentPresenter />
</ToggleButton>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
问题在于,当使用键盘导航时,焦点位于 ListBoxItem 而不是 ToggleButton 本身,这使得使用起来不直观。
如何更改焦点,使其正确位于按钮上而不是 ListBoxItem - 最好不要使用代码。
谢谢你, 伊多
【问题讨论】:
标签: wpf