Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Since you're using WPF I expect you don't plan to use a lot of animation, so a better way to do this would be with a Grid:

<!-- XAML -->
<Grid x:Name="Board">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
</Grid>

To place something in a cell:

void SetPosition(UIElement element, int x, int y)
{
    if (!Board.Children.Contains(element))
        Board.Children.Add(element);
    Grid.SetColumn(element, x);
    Grid.SetRow(element, y);
}

You could also use a UniformGridUniformGrid.

A completely data-driven answer can be found in StackOverflow: WPF controls needed to build chess applicationStackOverflow: WPF controls needed to build chess application

Since you're using WPF I expect you don't plan to use a lot of animation, so a better way to do this would be with a Grid:

<!-- XAML -->
<Grid x:Name="Board">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
</Grid>

To place something in a cell:

void SetPosition(UIElement element, int x, int y)
{
    if (!Board.Children.Contains(element))
        Board.Children.Add(element);
    Grid.SetColumn(element, x);
    Grid.SetRow(element, y);
}

You could also use a UniformGrid.

A completely data-driven answer can be found in StackOverflow: WPF controls needed to build chess application

Since you're using WPF I expect you don't plan to use a lot of animation, so a better way to do this would be with a Grid:

<!-- XAML -->
<Grid x:Name="Board">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
</Grid>

To place something in a cell:

void SetPosition(UIElement element, int x, int y)
{
    if (!Board.Children.Contains(element))
        Board.Children.Add(element);
    Grid.SetColumn(element, x);
    Grid.SetRow(element, y);
}

You could also use a UniformGrid.

A completely data-driven answer can be found in StackOverflow: WPF controls needed to build chess application

Source Link
jzx
  • 3.8k
  • 2
  • 26
  • 38

Since you're using WPF I expect you don't plan to use a lot of animation, so a better way to do this would be with a Grid:

<!-- XAML -->
<Grid x:Name="Board">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
</Grid>

To place something in a cell:

void SetPosition(UIElement element, int x, int y)
{
    if (!Board.Children.Contains(element))
        Board.Children.Add(element);
    Grid.SetColumn(element, x);
    Grid.SetRow(element, y);
}

You could also use a UniformGrid.

A completely data-driven answer can be found in StackOverflow: WPF controls needed to build chess application