In WPF I can specify that a control container is a Focus Scope and that tab navigation should cycle through the controls (i.e. when I tab out of the final control, focus will return to the first):
<Border FocusManager.IsFocusScope="True" KeyboardNavigation.TabNavigation="Cycle">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox x:Name="Editor" Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
What I am trying to do is to detect when focus leaves the final field. Without knowing precisely the number of controls within the focus scope, does anyone know if this is possible?
For the sake of closing off this question, I’m changing my comment to an answer. The solution was essentially to keep a record of selected item within the view model and react to changes to that. As a general rule I don’t think the view model should be aware of control focus, but in this case I think it is required as the view model needs to react to focus changes.