title: MVVM : Binding Commands with Collection to Listbox in WPF
body: <p>i have a list box in which there are different controls like button , text box etc in its item template, i have a collection which i bind with listbox, it works fine , but now i want to move my code to MVVM , and i write some commands in my View Model for clicks events of buttons , how can i bind my collection + my commands to list box ??? because commands are not in the collection, this is the Data Template for my list Box </p>
  
  <pre><code>&lt;DataTemplate x:Key="listItemTemplate"&gt;
      &lt;Grid ShowGridLines="False"&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;DockPanel Grid.Row="0" Name="commentsPanel" LastChildFill="False" MinWidth="350"&gt;
              &lt;TextBlock  Name="txtUserName" IsEnabled="False" Text="{Binding UserName}" 
                        Width="Auto" DockPanel.Dock="Left" Foreground="GhostWhite" Margin="0,6,0,0"&gt;&lt;/TextBlock&gt;
  
              &lt;TextBlock Name="txtDate" IsEnabled="False" Text="{Binding CreateDt}"
                        Width="Auto" DockPanel.Dock="Left" Foreground="Green" Margin="4,6,0,0"&gt;&lt;/TextBlock&gt;
  
              &lt;StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Width="{Binding EditPanelWidth}" x:Name="EditDeletePanel" Visibility="{Binding ButtonVisibilityText }"&gt;
                  &lt;Button Name="btnEdit" Content="Edit" Width="Auto" DockPanel.Dock="Right" Height="20"
                    Click="btnEdit_Click_1" Margin="4,4,0,4" Foreground="GhostWhite" VerticalContentAlignment="Top" Visibility="{Binding ButtonVisibilityText}"&gt;&lt;/Button&gt;
  
                  &lt;Button Name="btnDelete" Content="Delete" Width="Auto" Height="20" VerticalContentAlignment="Top" DockPanel.Dock="Right" Visibility="{Binding ButtonVisibilityText}"
                  Click="btnDelete_Click_1" Margin="4"&gt;&lt;/Button&gt;
  
              &lt;/StackPanel&gt;
  
              &lt;StackPanel DockPanel.Dock="Right" Orientation="Horizontal" x:Name="SaveCancelPanel" Visibility="{Binding CancelSaveEnableText}"&gt;
                  &lt;Button Name="btnSave" Content="Save" Width="Auto" Height="20" DockPanel.Dock="Right" 
                  Click="btnSave_Click_1" Margin="4"&gt;&lt;/Button&gt;
  
                  &lt;Button Name="btnCancel" Content="Cancel" Height="20" Width="Auto" DockPanel.Dock="Right" 
                  Click="btnCancel_Click_1" Margin="4"&gt;&lt;/Button&gt;
  
              &lt;/StackPanel&gt;
          &lt;/DockPanel&gt;
          &lt;dxe:TextEdit ShowBorder="False" Grid.Row="1" Name="txtComment" Width="Auto" Foreground="Red"  
                    TextWrapping="WrapWithOverflow" EditValue="{Binding Note}" IsEnabled="{Binding IsCommentTextEnable}"&gt;
  
          &lt;/dxe:TextEdit&gt;
          &lt;dxe:TextEdit Text=".............." Grid.Row="2" ShowBorder="False" IsEnabled="False"&gt;
  
          &lt;/dxe:TextEdit&gt;
      &lt;/Grid&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>and here is the collection + my commands which i want to bind to buttons , </p>
  
  <pre><code>public ICommand CancelCommand
  {
      get { return _cancelCommand ?? (_cancelCommand = new CommandHandler(Cancel)); }
      set { _cancelCommand = value; }
  }
  
  
  
  public TList&lt;ProgramNote&gt; NotesCollection
  {
      get { return _notes; }
      set
      {
          _notes = value;
          RaisePropertyChanged("NotesCollection");
      }
  }
  </code></pre>
  
  <p>I know i can use this code to bind my commands with button </p>
  
  <pre><code>&lt;Button Command={Binding CancelCommand}
  </code></pre>
  
  <p>but this command is not present in the collection , i am new in MVVM , kindly help , may be i am missing some little thing to bind my commands , but i am confused that how to add commands in my collection , so that i can get them in my view </p>