title: Checkers and movable figures WPF
body: <p>I'm doing simple checkers game in C# and WPF. The problem i am facing has to do with displaying properly the content. I've got  a board, i can put pawns wherever I want on it, but unfortunately I cannot make any figure move (My vision is that player clicks on Pawn/Queen - the figure is now movable with cursor - then he puts it on right spot). I tried removing Image from parent and adding to different grid and some other ideas - however I failed. </p>
  
  <pre><code>&lt;Window x:Class="Checkers.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:Checkers"
      Title="Checkers" WindowStyle="ThreeDBorderWindow" MinWidth="800" MinHeight="680"  Width="800" Height="680" Icon="C:\Users\NAME\Documents\Visual Studio 2012\Projects\Checkers\Checkers\Resources\package_games_board.ico" WindowStartupLocation="CenterScreen" &gt;
  &lt;Window.Resources&gt;
      &lt;DataTemplate DataType="{x:Type local:Pawn}"&gt;
          &lt;Image Source="{Binding ImageSource}" MouseDown="ItemsControl_MouseDown_1" MouseMove="helo_MouseMove_1" Name="helo" Tag="{Binding Reference}"/&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  
  &lt;Grid x:Name="LayoutRoot" Background="MidnightBlue"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="20"/&gt;
          &lt;RowDefinition Height="600"/&gt;
          &lt;RowDefinition Height="*" /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;Menu Grid.Row="0" Grid.Column="1" Height="18" VerticalAlignment="Top" Margin="0,0,0,0"/&gt;
      &lt;Grid Grid.Row="1"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="600" /&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;UniformGrid Grid.Column="1" x:Name="CheckersBoard" Rows="8" Columns="8"  SnapsToDevicePixels="False"/&gt;
  
          &lt;ItemsControl Grid.Column="1" ItemsSource="{Binding}"&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate x:Name="GridBoard"&gt;
                      &lt;Grid IsItemsHost="True"&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                              &lt;RowDefinition/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                              &lt;ColumnDefinition/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                      &lt;/Grid&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
              &lt;ItemsControl.ItemContainerStyle&gt;
                  &lt;Style TargetType="ContentPresenter"&gt;
                      &lt;Setter Property="Grid.Row" Value="{Binding Row}"/&gt;
                      &lt;Setter Property="Grid.Column" Value="{Binding Column}"/&gt;
                  &lt;/Style&gt;
              &lt;/ItemsControl.ItemContainerStyle&gt;
          &lt;/ItemsControl&gt;
  
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>    </p>
  
  <p>Then I have class of Pawn:</p>
  
  <pre><code>public class Pawn : INotifyPropertyChanged
  {
  
      public bool IsBlack { get; set; }
  
      public Pawn Reference { get; set; }
      private int _row;
      public Pawn()
      {
          Reference = this;
      }
  
      public int Row
      {
          get { return _row; }
          set
          {
              _row = value;
              OnPropertyChanged("Row");
          }
      }
  
      private int _column;
      public int Column
      {
          get { return _column; }
          set
          {
              _column = value;
              OnPropertyChanged("Column");
          }
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
      protected virtual void OnPropertyChanged(string propertyName)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
      }
  
      public string ImageSource 
      {
          get { return "C:\\Users\\NAME\\Documents\\Visual Studio 2012\\Projects\\Checkers\\Checkers\\Resources\\" + (IsBlack ? "black" : "white") + "_transparent.png"; }
      }
  
  }
  </code></pre>
  
  <p>And the main code (rest is not the case):</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      private ObservableCollection&lt;Pawn&gt; Pawns;
      private void ShowBoard()
      {
          SolidColorBrush scb_white = (SolidColorBrush)(new BrushConverter().ConvertFrom("#8080FF"));
          SolidColorBrush scb_dark = (SolidColorBrush)(new BrushConverter().ConvertFrom("#004A95"));
          for (int i = 0; i &lt; 64; i++)
              CheckersBoard.Children.Add(new Rectangle() { Name = "field"+i, Stroke=Brushes.Black, Fill = (i + 1 + i / 8) % 2 == 0 ? scb_white : scb_dark });
  
          Pawns.Add(new Pawn() { Row = 0, Column = 0, IsBlack = true });
          Pawns.Add(new Pawn() { Row = 0, Column = 2, IsBlack = false });
          Pawns.Add(new Pawn() { Row = 0, Column = 4, IsBlack = true });
      }
  
      public MainWindow()
      {
          Pawns = new ObservableCollection&lt;Pawn&gt;();
          InitializeComponent();
          DataContext = Pawns;
          ShowBoard();
      }
  
      Mouse handlers ...
  </code></pre>
  
  <p>Does someone know the solution?</p>