title: How to Select All CheckBox of a Column on DataGrid Header CheckBox in WPF DataGrid
body: <p>Im facing an issue with WPF DataGrid Checkboxes C#.</p>
  
  <p>Im not finding a way to select all cell template checkboxes when the header template checkbox is selected. in viewmodel its working fine. it get select all but in view it no showing any selected checkbox sign/mark on checked header checkbox.The problem I'm stuck with is related to checkbox in DataGrid(WPF)</p>
  
  <p><a href="https://i.stack.imgur.com/NBsrv.gif" rel="nofollow noreferrer">click this link I want to do same like this</a>
  My XAML code :</p>
  
  <pre><code>&lt;DataGrid x:Name="DgLines" ItemsSource="{Binding OpcUaEndpoints}"
            MouseDoubleClick="DgLines_MouseDoubleClick" SelectionMode="Extended"  
            DataContext="{Binding}"  IsReadOnly="True" Grid.ColumnSpan="5"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn
              &lt;DataGridTemplateColumn.HeaderTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;CheckBox Name="ckbSelectedAll"  Checked="ckbSelectedAll_Checked" Unchecked="ckbSelectedAll_Unchecked"
                                IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"&gt;&lt;/CheckBox&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.HeaderTemplate&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;CheckBox Name="cbkSelect" Checked="cbkSelect_Checked" Unchecked="cbkSelect_Unchecked"
                                IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
  
          &lt;!--&lt;DataGridTextColumn Width="200" Header="Id" Binding="{Binding Id }" /&gt;--&gt;
  
          &lt;DataGridTextColumn Width="200" Header="Name" Binding="{Binding Name}"/&gt;
          &lt;DataGridTextColumn Width="500" Header="Description" Binding="{Binding Description}"/&gt;
          &lt;DataGridTextColumn Width="500" Header="Lines" Binding="{Binding Endpoint}"/&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>ViewModelCode:</p>
  
  <pre><code>private void ckbSelectedAll_Unchecked(object sender, RoutedEventArgs e)
  {
      //  this.DgLines.UnselectAll();
      foreach (AddLinesViewModel c in DgLines.ItemsSource)
      {
          c.IsSelected = false;
      }
  }
  
  private static OpcUaEndpointsListViewModel _instance;
  private static readonly object Padlock = new object();
  private ICommand _addCommand;
  private ICommand _uncheckCommand;
  private ICommand _searchcommand;
  private ObservableCollection&lt;AddOpcUaEndpointsViewModel&gt; _endpoint;
  public string _charNameFromTB;
  
  public OpcUaEndpointsListViewModel()
  {
      BindDataGrid();
  }
  
  public static OpcUaEndpointsListViewModel Instance
  {
      get
      {
          lock (Padlock)
          {
              return _instance ?? (_instance = new OpcUaEndpointsListViewModel());
          }
      }
  }
  
  /// &lt;summary&gt;
  ///     //OPC UA Endpoint List
  /// &lt;/summary&gt;
  public ObservableCollection&lt;AddOpcUaEndpointsViewModel&gt; OpcUaEndpoints
  {
      get =&gt; _endpoint;
      set
      {
          if (OpcUaEndpoints == value)
          {
              _endpoint = value;
              OnPropertyChanged("OpcUaEndpoints");
          }
      }
  }
  
  public string CharNameFromTB
  {
      get { return _charNameFromTB; }
      set
      {
          _charNameFromTB = value;
          OnPropertyChanged("CharNameFromTB");
      }
  }
  
  public ICommand AddCommand
  {
      get { return _addCommand ?? (_addCommand = new RelayCommand(p =&gt; ExecuteAddCommand())); }
  }
  
  public ICommand SearchCommand
  {
      get { return _searchcommand ?? (_searchcommand = new RelayCommand(p =&gt; ExecuteSearchCommand())); }
  }
  
  private void ExecuteSearchCommand()
  {
      BindDataGridsearch();
  }
  
  private void BindDataGrid()
  {
      var opcendptsModel = opcUaEndpointsService.GetAll();
      _endpoint = new ObservableCollection&lt;AddOpcUaEndpointsViewModel&gt;(opcendptsModel.Select(p =&gt; new AddOpcUaEndpointsViewModel(p)));
  }
  </code></pre>