Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:34:47+00:00 2026-05-23T17:34:47+00:00

I have a grid and a button. I want to be able to press

  • 0

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.

A WPF grid and a button

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:34:48+00:00Added an answer on May 23, 2026 at 5:34 pm

    I think you’re looking for the Attached Property FocusManager.IsFocusScope.

    By setting it to true on the StackPanel, the Button'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

    <StackPanel Grid.Row="1"
                FocusManager.IsFocusScope="True" >
        <Button Width="Auto" Height="Auto" HorizontalAlignment="Left">Cut</Button>
        <Button Width="Auto" Height="Auto" HorizontalAlignment="Left">Copy</Button>
        <Button Width="Auto" Height="Auto" HorizontalAlignment="Left">Paste</Button>
    </StackPanel>
    

    Or in your case, just

    <StackPanel Grid.Row="1"
                FocusManager.IsFocusScope="True">
        <Button Margin="3,3,3,3" Width="Auto" Height="Auto" HorizontalAlignment="Left">_Press Me!</Button>
    </StackPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have grid of button. I want to a button to be clicked(invoke click
I have a grid, which I want to add a button at the top
I have a grid filled with notes and I want to be able to
I have a grid of images/buttons, and I want the user to be able
I have a listbox with a datatemplate <Button Name=ButtonSortDate Content=Date Grid.Column=1 Click=ButtonSortDateClick /> <Button
I have a xaml code: <Grid> <WrapPanel> <TextBox ></TextBox> <Button Content=GetIt /> </WrapPanel> </Grid>
I have a grid that has multiple rows. I want to hide/show one of
I have two queries that I want to be able to run on a
Hai presently i have grid like this. <Grid Name=tGrid1 Grid.Row=0 Background=Black > </Grid> <Grid
I want to have a grid type layout of image views. To begin i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.