![](/img/trans.png)
[英]How to automatically move focus when selectedindex tab change in Tab control?
[英]How to latch the SelectedIndex on a WPF listbox when a child control has focus
我目前有
<Style x:Key="ListboxItemStyle" TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
但是問題是當我對UI焦點進行其他控制時,SelectedIndex返回-1
。 我正在尋找的行為是當孩子獲得焦點時選擇了ListBoxItem
但當孩子失去焦點時不會重置。
用EventTrigger
替換Trigger
,然后IsSelected
不會返回到原始狀態:
<EventTrigger RoutedEvent="PreviewGotKeyboardFocus">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
從MSDN
與Trigger不同,EventTrigger沒有終止狀態的概念,因此一旦引發事件的條件不再成立,該動作將不會撤消。
PS:我只為SelectionMode="Single"
嘗試過此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.