title: c# mvvm databind for multiple click events not working
body: <p>i have made an picross application in c# als my secund c# application.
  i am trying to keep it mvvm. but have a little problem with this.</p>
  
  <p>i have an array of rectangles en when someone clicks 1 of theses rectangles the status of this one needs to be changed(color change).</p>
  
  <p>i have managed to do this in a non mvvm way but really want to make is mvvm.</p>
  
  <p>so the code.
  first the xaml code.</p>
  
  <pre><code>&lt;Window x:Class="View.CreatePuzzle"
      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:View"
      xmlns:controls="clr-namespace:View.Controls"
      mc:Ignorable="d"
      Title="CreatePuzzle" Height="450" Width="800"&gt;
  &lt;Window.Resources&gt;
      &lt;VisualBrush x:Key="myBrush"&gt;
          &lt;VisualBrush.Visual&gt;
              &lt;Grid&gt;
                  &lt;Rectangle Fill="Red"/&gt;
                  &lt;Image Source="Images/backgroundmain.jpg"/&gt;
              &lt;/Grid&gt;
          &lt;/VisualBrush.Visual&gt;
      &lt;/VisualBrush&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid Background="{StaticResource myBrush}" RenderTransformOrigin="0.508,0.819" Height="450" Margin="10,0,10,0"&gt;
  
      &lt;Grid.ColumnDefinitions&gt;
  
          &lt;ColumnDefinition Width="200"/&gt;
          &lt;ColumnDefinition Width="600"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;StackPanel&gt;
          &lt;TextBlock Grid.Column="0" Text="your name" /&gt;
          &lt;TextBox Grid.Column="0" Text="{Binding Author}" /&gt;
      &lt;TextBlock Grid.Column="0" Text="width" /&gt;
          &lt;controls:numberinput x:Name="widthfield" Grid.Column="1"  Value="{Binding puzzlewidth}"&gt;
          &lt;/controls:numberinput&gt;
      &lt;TextBlock Grid.Column="0" Text="height" /&gt;
          &lt;controls:numberinput x:Name="heightfield" Grid.Column="0" Value="{Binding puzzleheight}"&gt;
          &lt;/controls:numberinput&gt;
  
          &lt;Button Grid.Column="0" Height="25" Content="generate puzzle" 
          Command="{Binding Path=generatefield}"/&gt;
      &lt;/StackPanel&gt;
  
      &lt;controls:PiCrossControl HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1" x:Name="picrossControl" ColumnConstraints="{Binding ColumnConstraints}" RowConstraints="{Binding RowRonstraints }" Grid="{Binding Grid}" &gt;
          &lt;controls:PiCrossControl.SquareTemplate&gt;
              &lt;DataTemplate &gt;
                  &lt;Rectangle Width="32" Height="32" Stroke="Black" MouseRightButtonDown="Rectangle_MouseRightButtonDown" MouseWheel="Rectangle_MouseWheel"&gt;
                      &lt;Rectangle.InputBindings&gt;
                          &lt;MouseBinding Gesture="LeftClick" Command="{Binding Path=Rectangle_MouseLeftButtonDown}"/&gt;
                      &lt;/Rectangle.InputBindings&gt;
                      &lt;Rectangle.Fill&gt;
                          &lt;Binding Path="Contents.Value"  UpdateSourceTrigger="PropertyChanged"&gt;
                              &lt;Binding.Converter&gt;
                                  &lt;local:SquareConverter Empty="White" Filled="Black" Unknown="green" /&gt;
                              &lt;/Binding.Converter&gt;
                          &lt;/Binding&gt;
                      &lt;/Rectangle.Fill&gt;
                  &lt;/Rectangle&gt;
              &lt;/DataTemplate&gt;
          &lt;/controls:PiCrossControl.SquareTemplate&gt;
  
      &lt;/controls:PiCrossControl&gt;
          &lt;Button Grid.ColumnSpan="2" Height="50" Content="create puzzle" 
          Command="{Binding Path=createpuzzle}" Margin="0,340,0,0"/&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>here is one of the methodes is want to take out of the xaml.cs</p>
  
  <pre><code>    private void Rectangle_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
      {
          Rectangle rectangle = (Rectangle)sender;
          IPlayablePuzzleSquare square = (IPlayablePuzzleSquare)rectangle.DataContext;
         square.Contents.Value = Square.EMPTY;
      }
  </code></pre>
  
  <p>and the view model methode i wanna use to replace it with:</p>
  
  <pre><code>        public void Rectangle_MouseLeftButtonDown(object sender )
      {
          Debug.WriteLine("leftmousevent in vm");
  
      }
  </code></pre>
  
  <p>so when i run this code i get te following error for every rectangle :</p>
  
  <pre><code>System.Windows.Data Error: 40 : BindingExpression path error: 'Rectangle_MouseLeftButtonDown' property not found on 'object' ''PlayablePuzzleSquare' (HashCode=36468595)'. BindingExpression:Path=Rectangle_MouseLeftButtonDown; DataItem='PlayablePuzzleSquare' (HashCode=36468595); target element is 'MouseBinding' (HashCode=10961125); target property is 'Command' (type 'ICommand')
  </code></pre>
  
  <p>i hope someone can help me.
  note i am pretty new to c# but have more java experience.</p>
  
  <p>thanks in advance
  jef uytterhoeven</p>