Home c# C # wpf chess, drawing board

C # wpf chess, drawing board

Author

Date

Category

It is required to draw the field with which in the subsequent can be operated through the logic described in the code. In the logic of the program, the board and arrangement on it are described in the form of a two-dimensional array. There is an idea with canvas and rectangle , but I do not understand how to label these Rectangle and paint them according to the board, then tie the figures based on again, two-dimensional array.

Link to rap: https://github.com/anyast103/megachess_game


Answer 1, Authority 100%

This answer does not depend on the reference in the question, a full example of using UI in WPF “from scratch”.

I’m a disadvantage, but below the following example is not used Canvas , not Rectangle .

All that I learned from the repository is that you are very weakly familiar with WPF, quite unfamiliar with the MVVM design template. And you need to download the skills C # in principle. But it’s all right when you learn. Therefore, I immediately show you how to implement correctly in WPF chessboard. At the same time, only the UI part of the game will be shown without reference to any gaming logic. Gaming logic You will have to fasten yourself.

So, TK:

  • draw in the interface chessboard with coordinate tags
  • Post on it chess pieces
  • Implement the movement of chess figures in free cells by the user using the mouse

It looks simple, drove:

Chessplate with chess in WPF

1. MVVM, InotifyPropertyChanged , ICOMMAND

If briefly, then MVVM (Model View ViewModel) is an application design template that allows them to develop them through the full division of data logic (Model), interface (View) and data interaction logic ViewModel). All of these 3 layers are developed separately. In my particular case, I will not have Model as such, so it will be a little simpler than full MVVM.

InotifyPropertyChanged – you need to report the interface that the data has be changed by calling the propertychanged event. At the beginning it will look like magic, but the whole magic part here is that the interface itself signs this event automatically. It is stitched in WPF, you just need to use. For the implementation of this interface will be a simple class, it is necessary to just add to the project.

Public Class NotifyPropertyChanged: indoTifyPropertyChanged
{
  Public Event PropertyChangeDeventHandler PropertyChanged;
  PROTECTED VIRTUAL VOID OnPropertyChanged ([CallermemberName] String PropertyName = NULL)
    = & gt; PropertyChanged? .Invoke (This, New PropertyChangeDeventargs (PropertyName));
}

ICOMMAND – Goodbye click event handlers, the team has more features, later you will see them. For convenient use of commands, this auxiliary class was created. It is also just necessary to add to the project.

Public Class RelayCommand: ICommand
{
  Private Readonly Action & LT; Object & GT; _Execute;
  Private Readonly Func & Lt; Object, Bool & GT; _canexecute;
  Public Event Eventhandler Canexecutechanged
  {
    Add {CommandManager.RequerySuggened + = Value; }
    Remove {CommandManager.RequerySuggened - = Value; }
  }
  Public RelayCommand (Action & LT; Object & GT; Execute, Func & Lt; Object, Bool & GT; Canexecute = NULL)
  {
    _Execute = execute;
    _Canexecute = Canexecute;
  }
  Public Bool Canexecute (Object Parameter) = & gt; _canexecute == null || _Canexecute (Parameter);
  Public Void Execute (Object Parameter) = & gt; _Execute (Parameter);
}

2. Data Structure

The chess field cell can be only 13 states: empty or on it 1 out of 12 types of chess pieces (6 white and 6 black). To list all states, I will create (suddenly) listing.

public enum state
{
  Empty, // empty
  Whiteking, // King
  Whitequeen, // Queen
  Whiteerook, // Rye
  WhitekNight, // horse
  Whitebishop, // Elephant
  WhitePawn, // Pawn
  Blackking
  BlackQueen,
  Blackrook,
  Blackknight,
  BlackBishop,
  BlackPawn.
}

Cell that contains this condition looks like this. By the way, here it is immediately NotifyPropertyChanged and an easy way to use it.

Public Class Cell: NotifyPropertyChanged
{
  Private state _state;
  Private Bool _Active;
  Public State State.
  {
    get = & gt; _state;
    SET.
    {
      _state = value;
      OnPropertyChanged (); // inform the interface that the value changed so that the Internet shrew in this place
    }
  }
  Public Bool Active // ​​It will show that the cell is highlighted by the user.
  {
    get = & gt; _Active;
    SET.
    {
      _Active = Value;
      OnPropertyChanged ();
    }
  }
}

Chess field will be a “cunning” class, on the one hand it will be a two-dimensional array of State , on the other – the field with CELL cells . The first is for you so that you can easily write a type Board type [0] = state.whitequeen . The second is for the interface so that he can all these states track.

Here everything is simple, an array, the indexer state and ienumerable & lt; cell & gt; to interface (ItemScontrol ) could do it.

Public Class Board: Ienumerable & lt; cell & gt;
{
  Private Readonly Cell [,] _area;
  Public State This [INT ROW, INT COLUMN]
  {
    get = & gt; _area [row, column] .state;
    SET = & GT; _area [row, column] .state = value;
  }
  Public Board ()
  {
    _area = new cell [8, 8];
    for (int i = 0; i & lt; _area.getlength (0); i ++)
      for (int j = 0; j & lt; _aarea.getlength (1); j ++)
        _area [i, j] = new cell ();
  }
  Public Ienumerator & LT; Cell & GT; GetEnumerator ()
    = & gt; _area.cast & lt; cell & gt; (). GetEnumerator ();
  Ienumerator Ienumerable.GetEnumerator ()
    = & gt; _aarea.geteNumerator ();
}

I am a hook in Europe, because a lot of codes, and the answer is not rubber.

3. ViewModel

Here is the whole basic interface interaction logic, actually this is the main and most interesting part of the application that you have to refine.

Public Class MainViewModel: notifypropertyChanged
{
  Private board _board = new board ();
  Private ICommand _NewGameCommand;
  Private ICommand _ClearCommand;
  Private ICommand _cellcommand;
  Public Ienumerable & LT; Char & GT; Numbers = & gt; "87654321";
  Public Ienumerable & LT; Char & GT; Letters = & gt; "Abcdefgh";
  Public Board Board
  {
    get = & gt; _Board;
    SET.
    {
      _Board = value;
      OnPropertyChanged ();
    }
  }
  Public iCommand NewGameCommand = & gt; _NewGameCommand ?? = New RelayCommand (Parameter = & gt;
  {
    SETUPBOARD ();
  });
  Public ICOMMAND CLEARCOMMAND = & GT; _ClearCommand ?? = New RelayCommand (Parameter = & gt;
  {
    Board = New Board ();
  });
  Public ICommand Cellcommand = & GT; _cellcommand ?? = New RelayCommand (Parameter = & gt;
  {
    Cell Cell = (Cell) Parameter;
    Cell ActiveCell = Board.Firstordefault (X = & GT; X.Active);
    If (Cell.State! = State.Empty)
    {
      If (! Cell.active & amp; & amp; ActiveCell! = NULL)
        ActiveCell.Active = false;
      Cell.Active =! Cell.Active;
    }
    ELSE If (ActiveCell! = NULL)
    {
      ActiveCell.Active = false; 
Cell.state = ActiveCell.state;
      ActiveCell.State = State.Empty;
    }
  }, Parameter = & gt; Parameter IS Cell Cell & Amp; & amp; (Board.any (X = & GT; X.Active) || Cell.State! = State.empty));
  Private Void Setupboard ()
  {
    Board Board = New Board ();
    Board [0, 0] = state.blackrook;
    Board [0, 1] = state.blackknight;
    Board [0, 2] = State.BlackBishop;
    Board [0, 3] = State.BlackQueen;
    Board [0, 4] = state.blackking;
    Board [0, 5] = State.BlackBishop;
    Board [0, 6] = state.blackknight;
    Board [0, 7] = State.Blackrook;
    for (int i = 0; i & lt; 8; i ++)
    {
      Board [1, i] = State.BlackPawn;
      Board [6, i] = state.whitepawn;
    }
    Board [7, 0] = state.whiterook;
    Board [7, 1] = state.whiteknight;
    Board [7, 2] = state.whitebishop;
    Board [7, 3] = state.whitequeen;
    Board [7, 4] = state.whiteking;
    Board [7, 5] = state.whitebishop;
    Board [7, 6] = state.whiteknight;
    Board [7, 7] = state.whiterook;
    Board = Board;
  }
  Public MainViewModel ()
  {
  }
}

To fasten ViewModel to the application, you need to see the MainWindow class as follows:

Public Partial Class Mainwindow
{
  Public Mainwindow ()
  {
    Initializecomponent ();
    Datactext = new mainviewmodel ();
  }
}

Yes, this is all class code Mainwindow , there is nothing more in it 🙂

4. Interface

The main part of the interface contains 2 buttons and draws a chessboard by 64 cells. In order for the interface to make a board from dark and light cells, I wrote a small converter. It is transmitted by the sequence number of the cell 0..63, and it returns true or false , where True is a dark cell. Each cell is also a button.

Public Class CellColorConverter: IVALUECONVERTER
{
  Public Object Convert (Object Value, Type Targettype, Object Parameter, CultureInfo Culture)
    = & gt; Value is int v & amp; & amp; (v% 2 == 0 ^ V / 8% 2 == 0);
  Public Object ConvertBack (Object Value, Type Targettype, Object Parameter, Cultureinfo Culture)
    = & gt; NULL;
}

Xaml main window turned out not difficult.

& lt; window x: class = "chessboard.mainwindow"
    XMLNS = "http://schemas.microsoft.com/winfx/2006/xaml/Presentation"
    XMLNS: X = "http://schemas.microsoft.com/winfx/2006/xaml"
    XMLNS: D = "http://schemas.microsoft.com/expression/blend/2008"
    XMLNS: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
    XMLNS: Local = "CLR-NAMESPACE: Chessboard"
    XMLNS: Controls = "CLR-NAMESPACE: ChessBoard.controls"
    MC: IGNORABLE = "D"
    Title = "wpf window" sizetocontent = "widthandheight" resizemode = "canminimize"
    D: DataContext = "{D: DesignInstance Local: MainViewModel, IsDesignTimeCreatable = True}"
    Snapstodevicepixels = "True" & gt;
  & lt; window.resources & gt;
    & lt; Local: CellColorConverter X: Key = "CellColorConverter" / & gt;
  & lt; /window.resources>
  & lt; grid & gt;
    & lt; grid.rowdefinitions & gt;
      & lt; rowdefinition Height = "AUTO" / & GT;
      & lt; rowdefinition Height = "AUTO" / & GT;
      & lt; rowdefinition Height = "AUTO" / & GT;
      & lt; rowdefinition Height = "AUTO" / & GT;
    & lt; /grid.rowdefinitions>
    & lt; grid.columndefinitions & gt;
      & lt; columndefinition width = "auto" / & gt;
      & lt; columndefinition width = "auto" / & gt;
      & lt; columndefinition width = "auto" / & gt;
    & lt; /grid.columndefinitions>
    & lt; stackpanel orientation = "horizontal" grid.column = "1" margin = "- 5.0" & gt;
      & lt; Button content = "New Game" margin = "5" padding = "10.5" Command = "{Binding NewGameCommand}" / & gt;
      & lt; Button content = "Clear" margin = "5" padding = "10.5" Command = "{Binding Clearcommand}" / & gt;
    & lt; / stackpanel & gt; 
& lt; ItemsControl Grid.Row = "2" ItemsSource = "{Binding Numbers}" Width = "21" & gt;
      & lt; ItemsControl.ItemTemplate & gt;
        & lt; DataTemplate & gt;
          & lt; Grid Height = "60" & gt;
            & lt; TextBlock Padding = "5.0" Text = "{Binding}" VerticalAlignment = "Center" TextAlignment = "Center" FontSize = "16" / & gt;
          & lt; / Grid & gt;
        & lt; / DataTemplate & gt;
      & lt; /ItemsControl.ItemTemplate>
    & lt; / ItemsControl & gt;
    & lt; ItemsControl Grid.Row = "1" Grid.Column = "1" ItemsSource = "{Binding Letters}" Height = "21" & gt;
      & lt; ItemsControl.ItemTemplate & gt;
        & lt; DataTemplate & gt;
          & lt; Grid Width = "60" & gt;
            & lt; TextBlock Text = "{Binding}" VerticalAlignment = "Center" TextAlignment = "Center" FontSize = "16" / & gt;
          & lt; / Grid & gt;
        & lt; / DataTemplate & gt;
      & lt; /ItemsControl.ItemTemplate>
      & lt; ItemsControl.ItemsPanel & gt;
        & lt; ItemsPanelTemplate & gt;
          & lt; StackPanel Orientation = "Horizontal" / & gt;
        & lt; / ItemsPanelTemplate & gt;
      & lt; /ItemsControl.ItemsPanel>
    & lt; / ItemsControl & gt;
    & lt; ItemsControl Grid.Row = "2" Grid.Column = "1" ItemsSource = "{Binding Board}" AlternationCount = "64" & gt;
      & lt; ItemsControl.ItemTemplate & gt;
        & lt; DataTemplate & gt;
          & lt; Button Width = "60" Height = "60" Command = "{Binding DataContext.CellCommand, RelativeSource = {RelativeSource AncestorType = Window}}" CommandParameter = "{Binding}" & gt;
            & lt; Button.Style & gt;
              & lt; Style TargetType = "{x: Type Button}" & gt;
                & lt; Setter Property = "OverridesDefaultStyle" Value = "True" / & gt;
                & lt; Setter Property = "Background" Value = "Bisque" / & gt;
                & lt; Setter Property = "BorderBrush" Value = "{x: Null}" / & gt;
                & lt; Setter Property = "BorderThickness" Value = "2" / & gt;
                & lt; Setter Property = "Template" & gt;
                  & lt; Setter.Value & gt;
                    & lt; ControlTemplate & gt;
                      & lt; Border Background = "{TemplateBinding Background}" & gt;
                        & lt; Border BorderThickness = "{TemplateBinding BorderThickness}" BorderBrush = "{TemplateBinding BorderBrush}" & gt;
                          & lt; controls: ChessPiece Piece = "{Binding State}" / & gt;
                        & lt; / Border & gt;
                      & lt; / Border & gt;
                    & lt; / ControlTemplate & gt;
                  & lt; /Setter.Value>
                & lt; / Setter & gt;
                & lt; Style.Triggers & gt;
                  & lt; DataTrigger Binding = "{Binding (ItemsControl.AlternationIndex), RelativeSource = {RelativeSource AncestorType = ContentPresenter}, Converter = {StaticResource CellColorConverter}}" Value = "True" & gt;
                    & lt; Setter Property = "Background" Value = "SandyBrown" / & gt;
                  & lt; / DataTrigger & gt;
                  & lt; DataTrigger Binding = "{Binding Active}" Value = "True" & gt;
                    & lt; Setter Property = "BorderBrush" Value = "Red" / & gt;
                  & lt; / DataTrigger & gt;
                & lt; /Style.Triggers>
              & lt; / Style & gt;
            & lt; /Button.Style>
          & lt; / Button & gt;
        & lt; / DataTemplate & gt;
      & lt; /ItemsControl.ItemTemplate>
      & lt; ItemsControl.ItemsPanel & gt;
        & lt; ItemsPanelTemplate & gt;
          & lt; UniformGrid Columns = "8" Rows = "8" / & gt;
        & lt; / ItemsPanelTemplate & gt;
      & lt; /ItemsControl.ItemsPanel>
    & lt; / ItemsControl & gt; 
& lt; ItemsControl Grid.Row = "3" Grid.Column = "1" ItemsSource = "{Binding Letters}" Height = "21" & gt;
      & lt; ItemsControl.ItemTemplate & gt;
        & lt; DataTemplate & gt;
          & lt; Grid Width = "60" & gt;
            & lt; TextBlock Text = "{Binding}" VerticalAlignment = "Center" TextAlignment = "Center" FontSize = "16" / & gt;
          & lt; / Grid & gt;
        & lt; / DataTemplate & gt;
      & lt; /ItemsControl.ItemTemplate>
      & lt; ItemsControl.ItemsPanel & gt;
        & lt; ItemsPanelTemplate & gt;
          & lt; StackPanel Orientation = "Horizontal" / & gt;
        & lt; / ItemsPanelTemplate & gt;
      & lt; /ItemsControl.ItemsPanel>
    & lt; / ItemsControl & gt;
    & lt; ItemsControl Grid.Row = "2" Grid.Column = "2" ItemsSource = "{Binding Numbers}" Width = "21" & gt;
      & lt; ItemsControl.ItemTemplate & gt;
        & lt; DataTemplate & gt;
          & lt; Grid Height = "60" & gt;
            & lt; TextBlock Padding = "5.0" Text = "{Binding}" VerticalAlignment = "Center" TextAlignment = "Center" FontSize = "16" / & gt;
          & lt; / Grid & gt;
        & lt; / DataTemplate & gt;
      & lt; /ItemsControl.ItemTemplate>
    & lt; / ItemsControl & gt;
  & lt; / Grid & gt;
& lt; / Window & gt;

And I would end on this, but since it will be very difficult for you to advance further with chess pieces without fully understanding the essence of data binding, so I immediately wrote a UserControl to which you pass the State , and he gives you a picture. Vector images – Path images are pulled from SVG files downloaded from iconfinder website. Type in Chess there and you’ll find them quickly.

User control code

public partial class ChessPiece: UserControl
{
  public static readonly DependencyProperty PieceProperty = DependencyProperty.Register ("Piece", typeof (State), typeof (ChessPiece));
  public State Piece
  {
    get = & gt; (State) GetValue (PieceProperty);
    set = & gt; SetValue (PieceProperty, value);
  }
  public ChessPiece ()
  {
    InitializeComponent ();
  }
}

And user control markup. Here I have applied every Kungfu styling technique in WPF that I know. 🙂

& lt; UserControl x: Class = "ChessBoard.Controls.ChessPiece"
       xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"
       xmlns: controls = "clr-namespace: ChessBoard.Controls"
       mc: Ignorable = "d"
       SnapsToDevicePixels = "True" & gt;
  & lt; UserControl.Resources & gt;
    & lt; DropShadowEffect x: Key = "BlackShadow" BlurRadius = "5" ShadowDepth = "0" Color = "Black" / & gt;
    & lt; DropShadowEffect x: Key = "WhiteShadow" BlurRadius = "5" ShadowDepth = "0" Color = "White" / & gt;
    & lt; Style TargetType = "Path" x: Key = "InvisiblePath" & gt;
      & lt; Setter Property = "Visibility" Value = "Collapsed" / & gt;
    & lt; / Style & gt;
    & lt; Style TargetType = "Path" x: Key = "Queen" BasedOn = "{StaticResource InvisiblePath}" & gt;
      & lt; Setter Property = "Data" Value = "M63,36c0,1.1-0.9,2-2,2H39c-1.1,0-2-0.9-2-2s0.9-2,2-2h22C62.1,34,63 , 34.9.63.36z M34.84h32c1.1.0.2-0.9.2-2s-0.9-2-2-2H34 c-1.1.0-2.0.9-2.2S32.9.84.34.84z M69.85H31c-2.2.0-4.1.8-4.4s1.8.4.4.4h38c2.2.0.4-1.8.4-4S71.2.85.69.85z M40.973.39 c- 0.277,29.941-2.637,33.513-3.583,40H62.61c-0.946-6.487-3.306-10.059-3.583-40H40.973z M34.965,23l3.89,10h22.291l3.89-10H34.965 z M65.424,22l2 .44-6.275l-3.729-1.45l-1.361,3.501c-1.851-0.886-5.641-1.543-10.218-1.724C53.432,15.318,54,14.231,54,13 c0-2.208-1.791-4-4- 4s-4.1.792-4.4c0.1.231.0.568.2.318.1.443.3.052c-4.577.0.181-8.367.0.838-10.218.1.724l-1.361-3.501 l-3.729.1.45L34.576.22H65.424z " / & gt;
    & lt; / Style & gt;
    & lt; Style TargetType = "Path" x: Key = "King" BasedOn = "{StaticResource InvisiblePath}" & gt; 
& lt; setter property = "data" value = "m37,36c0-1.1,0.9-2.2-2h22c1.1,0,2,0,9,2,2s-0.9,2-2.2h39c37.9,38,37 , 37.1.37,36Z M34.84H32C1.1,0,2-0.9.2-2S-0.9-2-2-2-2-234 C-1.1.0-2,0.9-2.2S32.9,84,34,84Z M69,85H31C-2.2.0-4,1.8-4.4S1.8,4,4,438C2.2,0,4-1.8.4-4S71.2,85,69,85Z M37,20L0.615,2H24 .77 L63.20L-11-4.231V11H2V7H-2V4H2V4.769L37,20Z M59,33L377-10H37.923L41,33H59Z M40.973.39 C-0.277,29.941-2.637,33.513-3.583,40H62. 61c-0.946-6.487-3.306-10.059-3.583-40h40.973z "/ & gt;
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "Rook" Basedon = "{StaticResource InvisiblePath}" & gt;
      & lt; setter Property = "Data" value = "M31,25V10H7V6H6V-6H12V6H6V-6H7V15C0,2.2-1.8.4-4,4H35C32.8.29,31,27.2,31,25Z M65,34C1.1,25 0.9.2-2s-0.9-2-2-2-2-2.0.9-2.2S0.9,2,2,2H65z M30.84H40C1.1.0.2-0.9,2-2S- 0.9-2-2-2-2-2-2-2.2S28.9.84.30.84Z M73,85H27 C-2.2.0-4,1.8-4.4S1.8,4,4, 4H46C2.2,0,4-1.8.4-4S75.2,85,73,85Z M68.262,79C66.464,72.751.62,70.139,62,35H38 C0.35.139-4.464,37.751-6.262,44H68. 262Z "/ & gt;
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "KNIGHT" Basedon = "{StaticResource InvisiblePath}" & gt;
      & lt; setter property = "data" value = "m31.375,40.219l1.249,1.562l-5.475,4.379c27.676,48.357,29.645,50,32,50c2.527,0,3622-1.884,4.954- 4.321L5.849-2.507 C2.944,2.45,7.337,2.296,10.097-0.465c2.924-2.924,2,924-7.682.0-10.606L0.707-0.707C1.605,1,605,2.49,3.74,2.49,6,6,6,64,2.49,6,01 C0,1.329-0.311,2.608-0.884,3.765L0.0C-0.196.0.396-0.425.0.775-0.681,1.139C-0.024.034-0.05.066-0.074.0.1 C-0.256.0.353-0.536.0.692-0.851 , 1.007C-0.276.0.276-0.57.0.523-0.873.0.752C-0.07.053-0.143.0.101-0.213.0.151 C-0.252,0.178-0.51.0.343-0.775.0.492C-1.508.0.843-3.216,1.203 -4.894,1.057c45.944,52.159,40.545,57,34,57l2,22H28 C0-9.957,2,698-18.563,5.535-25.822c64.908,57.412,58.751,60,52,60V-1C13.785.0, 25-11.215.25-25S65.785,9,52.9H-1V10H-1V-4H-7 C-3.866,0-7,3.134-7.7C0.1.831-16,7.76-16,16C0,3.38,2.395 , 6.199,5.58,6.855L31.375.40.219Z M45.485,20.143L1.029,1,715L-5.3 L-1.029-1.715L45.485,20.143Z M23.445,38.168L3-2L1.109,1,664 L-3,2L23.445,38.168Z M69,80C1.1,0,0,0,0,2S-0.9.2-2.2H31 C-1.1.0-2-0.9-2-2S0.9-2 , 2-2H69Z. M76,89C0,2.2.2-1.8.4-4.4-1.8-4-4S1.8-4.4-4H44C74.2,85,76,86.8,76,89Z "/ & GT;
    & lt; / style & gt;
    & lt; style targettype = "Path" X: Key = "Bishop" Basedon = "{StaticResource InvisiblePath}" & gt;
      & lt; setter Property = "Data" Value = "M37,40C0-1.1,0.9-2.2-2H22C1.1,0,2,0,9,2,2S-0.9.2-2.2H39C37.9,42,37 , 41.1.37,40Z M34.84H32C1.1.0.2-0.9.2-2S-0.9-2-2-2-2-234 C-1.1.0-2.0.9-2.2S32.9,84,34,84Z M69.85H31C-2.2.0-4,1,8-4.4S1.8,4,4,4H38C2.2,0,4-1.8.4-4S71.2,85,69,85Z M40.95.43 0.358,27.587-2.586.30.262-3.528.36H25.156C-0.942-5.738-3.17-8.413-3.528-36H40.95Z M59,37C0.0.4-6.4-11 C0-4.411-10.112-13.489-12.496- 19H-1.008C-0.871,2,015-2.776,4.506-4.842,7,072l4.24,848L-1.789.0.895L-3.834-7.668 C40.1,19.685,37,23.558,37,26C0,5,411 , 4,11H59Z "/ & gt;
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "pawn" basedon = "{staticresource invisiblepath}" & gt;
      & lt; setter property = "data" value = "m37,38c0-1.1,0,9-2.2-2h22c1.1,2,2,2,2,2c-0.9,2-2.2h39c37.9,40,37 , 39.1,37,38Z M34.84H32C1.1.0.2-0.9.2-2S-0.9-2-2-2-2-2-22 C-1.1.0-2.0.9-2.2S32.9,84,34,84Z M69,85H31C-2.2.0-4,1.8-4.4S1.8,4,4,438C2.2,0,4-1.8.4-4S71.2,85,69,85Z M50.35 C7.18, 0.13-5.82,13-13S57.18,9,50.9S-13,5.82-13,13S42.82.35.50,35Z M58,41H42C0,33.478-4.052,33.959-5.99.38H63.99 C62. 052,74.959,58,74.478,58,41Z "/ & gt;
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "Whitequeen" Basedon = "{StaticResource Queen}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "Whitequeen" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "path" x: key = "blackqueen" bandedon = "{staticResource Queen}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT; 
& lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {RelativeSource Ancestortype = UserControl}}" Value = "BlackQueen" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" X: Key = "Whiteking" Basedon = "{StaticResource King}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {RelativeSource Ancestortype = UserControl}}" Value = "Whiteking" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "Blackking" Basedon = "{StaticResource King}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT;
      & lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "Blackking" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" X: Key = "Whiterook" Basedon = "{StaticResource Rook}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "Whiteerook" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "Blackrook" Basedon = "{StaticResource Rook}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT;
      & lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {RelativeSource Ancestortype = UserControl}}" Value = "Blackrook" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "WhitekNight" Basedon = "{staticResource Knight}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "WhitekNight" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "path" x: key = "blackknight" bandedon = "{staticResource Knight}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT;
      & lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "Blackknight" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "Whitebishop" Basedon = "{StaticResource Bishop}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt; 
& lt; datatrigger binding = "{Binding Piece, relativeSource = {RelativeSource Ancestortype = UserControl}}" Value = "Whitebishop" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "BlackBishop" Basedon = "{StaticResource Bishop}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT;
      & lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "BlackBishop" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" x: Key = "WhitePawn" Basedon = "{StaticResource Pawn}" & gt;
      & lt; setter Property = "Fill" value = "White" / & gt;
      & lt; setter Property = "Effect" value = "{StaticResource Blackshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {relativeSource Ancestortype = UserControl}}" Value = "WhitePawn" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Path" X: Key = "BlackPawn" Basedon = "{StaticResource Pawn}" & gt;
      & lt; setter Property = "Fill" Value = "Black" / & GT;
      & lt; setter Property = "Effect" Value = "{StaticResource Whiteshadow}" / & gt;
      & lt; style.triggers & gt;
        & lt; datatrigger binding = "{Binding Piece, relativeSource = {RelativeSource Ancestortype = UserControl}}" Value = "BlackPawn" & gt;
          & lt; setter property = "visibility" value = "Visible" / & gt;
        & lt; / datatrigger & gt;
      & lt; /style.triggers>
    & lt; / style & gt;
    & lt; style targettype = "Controls: ChessPiece" & gt;
      & lt; setter Property = "Template" & gt;
        & lt; setter.value & gt;
          & lt; ControlTemplate & gt;
            & lt; viewbox & gt;
              & lt; grid width = "100" height = "100" & gt;
                & lt; path style = "{staticResource Whitequeen}" / & gt;
                & lt; path style = "{staticResource BlackQueen}" / & gt;
                & lt; path style = "{staticResource Whiteking}" / & gt;
                & lt; path style = "{staticResource blackking}" / & gt;
                & lt; Path Style = "{StaticResource Whiteerook}" / & gt;
                & lt; path style = "{staticResource Blackrook}" / & gt;
                & lt; path style = "{staticResource WhitekNight}" / & gt;
                & lt; path style = "{StaticResource Blackknight}" / & gt;
                & lt; path style = "{staticResource Whitebishop}" / & gt;
                & lt; path style = "{staticResource blackbishop}" / & gt;
                & lt; path style = "{StaticResource WhitePawn}" / & gt;
                & lt; path style = "{staticResource BlackPawn}" / & gt;
              & lt; / grid & gt;
            & lt; / viewBox & gt;
          & lt; / ControlTemplate & gt;
        & lt; /setter.value>
      & lt; / setter & gt;
    & lt; / style & gt;
  & lt; /usercontrol.resources>
  & lt; grid / & gt;
& lt; / usercontrol & gt;

That’s the whole application, there is nothing more.

Archive with a solution on Yandex.Disk – https://disk.yandex.ru/d/k9bxlysxj_jyca

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions