I have a grid and a button. I want to be able to press down-arrow to select a row, then click on the button, then press down-arrow to select the next row, then click on the button.
However, when I click on the button, the grid keyboard focus is no longer on the row.
Here’s an example. In this picture I have the third row selected. The behavior I want is: I mouse-click on Press Me, then press the keyboard down arrow once to select the fourth row. Instead, when I press down-arrow the top cell has a frame around it, and when I press it again the top row is selected.

How should I go about creating the behavior I need? I’ve tried editing the code behind to explicitly focus on the grid, but that didn’t work.
Here is the complete code for the example.
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="DcCharacters">
<x:XData>
<Characters xmlns="">
<Character HeroName="Catwoman" Identity="Selina Kyle" />
<Character HeroName="Batman" Identity="Bruce Wayne" />
<Character HeroName="Starman" Identity="Jack Knight" />
<Character HeroName="BlueBeetle" Identity="Jaime Reyes" />
</Characters>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid
Grid.Row="0"
ItemsSource="{Binding Source={StaticResource DcCharacters},
XPath=//Characters/Character}"
AutoGenerateColumns="False"
IsReadOnly="True"
>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding XPath=@HeroName}" />
<DataGridTextColumn Binding="{Binding XPath=@Identity}" />
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="1">
<Button Margin="3,3,3,3" Width="Auto" Height="Auto" HorizontalAlignment="Left">_Press Me!</Button>
</StackPanel>
</Grid>
</Window>
I think you’re looking for the Attached Property FocusManager.IsFocusScope.
By setting it to true on the
StackPanel, theButton's(or other Controls) within it won’t steal focus if they are clicked with the mouse. They will work like a Toolbar Button or Menu. You’ll still be able to tab to them though.Here is an example if you have three Buttons instead of one, Cut, Copy and Paste
Or in your case, just