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

  • SEARCH
  • Home
  • 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 7308245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:31:51+00:00 2026-05-28T23:31:51+00:00

I am a beginner at using WPF. I have wrote some xaml code in

  • 0

I am a beginner at using WPF.

I have wrote some xaml code in order to make a tic tac toe game.

I have a grid with 3 x 3 cells. I have put a button inside each cell of the grid.

I want to print out the position of the button with respect to the grid(i.e. row number and column number) when I press the button.

This is the xaml code :

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test Window" Height="500" Width="500" BorderBrush="#FA0D0D0D">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Button Name ="b1" Grid.Column=" 0" Grid.Row=" 0" Click="button_Click" />
    <Button Name ="b2" Grid.Column=" 0" Grid.Row=" 1" Click="button_Click" />
    <Button Name ="b3" Grid.Column=" 0" Grid.Row=" 2" Click="button_Click" />
    <Button Name ="b4" Grid.Column=" 1" Grid.Row=" 0" Click="button_Click" />
    <Button Name ="b5" Grid.Column=" 1" Grid.Row=" 1" Click="button_Click" />
    <Button Name ="b6" Grid.Column=" 1" Grid.Row=" 2" Click="button_Click" />
    <Button Name ="b7" Grid.Column=" 2" Grid.Row=" 0" Click="button_Click" />
    <Button Name ="b8" Grid.Column=" 2" Grid.Row=" 1" Click="button_Click" />
    <Button Name ="b9" Grid.Column=" 2" Grid.Row=" 2" Click="button_Click" />

</Grid>
</Window>

This is the C# code :

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    static int symbol;
    static int[][] game;
    public MainWindow()
    {
        InitializeComponent();
        symbol = 1;
        game = new int[3][];
        game[0] = new int[3];
        game[1] = new int[3];
        game[2] = new int[3];

    }

    private void button_Click(object sender, RoutedEventArgs e)
    {
        Button b = (Button)sender;
        if (symbol == 1)
        {
            b.Content = "x";
            symbol = 2;
        }
        else
        {
            b.Content = "o";
            symbol = 1;
        }
    }



}

}

Inside the button_Click method I want to print the row number and column number of the grid, where that button is placed. How can I obtain that information?

  • 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-28T23:31:52+00:00Added an answer on May 28, 2026 at 11:31 pm

    You may get the row and column index by these static methods of Grid:

    int row = Grid.GetRow(b);
    int column = Grid.GetColum(b);
    

    The methods return the values of the attached properties Grid.Row and Grid.Column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner at C++ but I have some experience using Java. I
I have a small-scale WPF application using VB.net as the code behind and I
I'm a beginner using python 3.2 and i have a book whos code is
I am a rank beginner in C#. I am currently using this code: objGraphics.Clear(SystemColors.Control);
I am a beginner in using Blend and WPF in general. I created three
I am a beginner in iOS development and have just start using the lasted
I am a beginner in using Rails and Git I have InstantRails installed and
I am a beginner at using openGL. I have used a program which I
I am beginner at using JSP and am following a tutorial. I have a
I am a beginner of Android apps and am using Eclipse. I have found

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.