Here's some sample code to reproduce the problem :
<StackPanel Width="100">
<ToggleButton Content="Test 1"/>
<ToggleButton Content="Test 2"/>
<ToggleButton Content="Test 3"/>
<StackPanel FocusManager.IsFocusScope="True">
<ToggleButton Content="Test 4"/>
<ToggleButton Content="Test 5"/>
<ToggleButton Content="Test 6"/>
</StackPanel>
</StackPanel>
If you tab through the ToggleButtons, the first 3 you can check/uncheck with the space bar without an issue because the keyboard focus remains on the item you change. But if you click/tab through boxes 4-6 that are in the focus scope and try to change them via the spacebar, the focus is reset outside of that focus scope, and subsequent spacebar presses get executed outside the focus scope.
How do I prevent the keyboard focus from leaving when changing data in a section where IsFocusScope=True
?
I found this behavior is "by design" for WPF. This post best explains it : https://stackoverflow.com/a/4954794/302677
The suggested solution of creating an attached property to implement your own focus scope handling is also in that link.