title: wpf datagrid expand all not working
body: <p>Hi have a Datagrid with groups, i added a button to Expand All groups but it's not working, all groups stay collapsed.</p>
  
  <p>I'm using PropertyChanged event Handler and a button with a Command</p>
  
  <p>Here is the xaml:</p>
  
  <pre><code>        &lt;StackPanel Grid.Row="0"&gt;
          &lt;Button x:Name="ExpandAll"  Content="Tout deplier" VerticalAlignment="Bottom" Command="{Binding ExpandAll}"/&gt;
          &lt;!-- This textblock text is updated by the Expanded property changed --&gt;
          &lt;TextBlock Text="{Binding Expanded}" /&gt;
      &lt;/StackPanel&gt;
      &lt;DataGrid x:Name="GrdLignes" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="0,0,0,0"
                Grid.Row="1" VerticalAlignment="Top" AutoGenerateColumns="False" CanUserAddRows="False"
                CanUserDeleteRows="False" ItemsSource="{Binding Lignes}" IsReadOnly="True"
                RowDetailsVisibilityMode="VisibleWhenSelected" RowHeaderWidth="25"&gt;
          &lt;DataGrid.GroupStyle&gt;
              &lt;GroupStyle&gt;
                  &lt;GroupStyle.ContainerStyle&gt;
                      &lt;Style TargetType="{x:Type GroupItem}"&gt;
                          &lt;Setter Property="Template"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                      &lt;Expander Background="Lavender" IsExpanded="{Binding Expanded}"&gt;
                                          &lt;Expander.Header&gt;
                                              &lt;StackPanel Orientation="Horizontal"&gt;
                                                  &lt;TextBlock Text="{Binding Path=Name}" Padding="0,0,5,0" FontWeight="Bold" /&gt;
                                                  &lt;TextBlock Text="{Binding Path=ItemCount}" Padding="0,0,5,0"/&gt;
                                                  &lt;TextBlock Text="Commandes"/&gt;
                                              &lt;/StackPanel&gt;
                                          &lt;/Expander.Header&gt;
                                          &lt;ItemsPresenter /&gt;
                                      &lt;/Expander&gt;
                                  &lt;/ControlTemplate&gt;
                              &lt;/Setter.Value&gt;
                          &lt;/Setter&gt;
                      &lt;/Style&gt;
                  &lt;/GroupStyle.ContainerStyle&gt;
              &lt;/GroupStyle&gt;
          &lt;/DataGrid.GroupStyle&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header="Pièce Achat" Binding="{Binding Path=Piece}" FontWeight="Bold"/&gt;
              &lt;DataGridTextColumn Header="Type" Binding="{Binding Path=TypeLabel}"&gt;
                  &lt;DataGridTextColumn.ElementStyle&gt;
                      &lt;Style TargetType="{x:Type TextBlock}"&gt;
                          &lt;Setter Property="Background" Value="{Binding Path=Type, Converter={StaticResource TypeToBrushConverter}}" /&gt;
                      &lt;/Style&gt;
                  &lt;/DataGridTextColumn.ElementStyle&gt;
              &lt;/DataGridTextColumn&gt;
              &lt;DataGridTextColumn Header="Statut" Binding="{Binding Path=StatutLabel}"&gt;
                  &lt;DataGridTextColumn.ElementStyle&gt;
                      &lt;Style TargetType="{x:Type TextBlock}"&gt;
                          &lt;Setter Property="Background" Value="{Binding Path=Statut, Converter={StaticResource StatutToBrushConverter}}" /&gt;
                      &lt;/Style&gt;
                  &lt;/DataGridTextColumn.ElementStyle&gt;
              &lt;/DataGridTextColumn&gt;
  
          &lt;/DataGrid.Columns&gt;
          &lt;DataGrid.RowDetailsTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;DataGrid RowHeaderWidth="25" ItemsSource="{Binding Path=Lignes}" AutoGenerateColumns="False" Margin="0" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"&gt;
                      &lt;DataGrid.Columns&gt;
                          &lt;DataGridTextColumn Header="Acheteur" Binding="{Binding Path=Acheteur}"/&gt;
                          &lt;DataGridTextColumn Header="Pièce" Binding="{Binding Path=Piece}"/&gt;
                          &lt;DataGridTextColumn Header="Client" Binding="{Binding Path=Client}"/&gt;
                          &lt;DataGridTextColumn Header="Ref" Binding="{Binding Path=ArRef}"/&gt;
                          &lt;DataGridTextColumn Header="Ref Fourn" Binding="{Binding Path=RefFourn}"/&gt;
                          &lt;DataGridTextColumn Header="Designation" Binding="{Binding Path=Designation}"/&gt;
                          &lt;DataGridTextColumn Header="Qte" Binding="{Binding Path=CmQte}"/&gt;
                          &lt;DataGridTextColumn Header="Vendeur" Binding="{Binding Path=Vendeur}"/&gt;
                      &lt;/DataGrid.Columns&gt;
                  &lt;/DataGrid&gt;
              &lt;/DataTemplate&gt;
          &lt;/DataGrid.RowDetailsTemplate&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Here is the viewModel:</p>
  
  <pre><code>public class MainViewModel : INotifyPropertyChanged
  {
      private bool _expanded = false;
  
      public bool Expanded
      {
          get { return _expanded; }
          set
          {
              _expanded = value;
              OnPropertyChanged("Expanded");
          }
      }
  
      public ICommand ExpandAll { get; set; }
  
      public MainViewModel()
      {
          ExpandAll = new Command(ExpandAllAction);
      }
  
      private void ExpandAllAction(object parameters)
      {
          Expanded = true;
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      private void OnPropertyChanged(string propertyName)
      {
          PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>