title: Binding DataGrid Expander when using ListCollectionView
body: <p>I'm trying to get all the DataGrid Expanders to open and close using a open/close button like the example below. Problem is when I'm using a single boolean to bind to this will break when I'm opening/closing a single expander.</p>
  
  <p>I'm using a ListCollectionView to set the GroupingDescription. </p>
  
  <p>I guess I'm looking for a solution to somehow get the Expander to play nice?</p>
  
  <p><a href="https://i.stack.imgur.com/uFl5K.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uFl5K.gif" alt="Example"></a></p>
  
  <h2>View</h2>
  
  <pre><code>&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 IsExpanded="{Binding Source={StaticResource proxy}, Path=Data.Expanded, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"&gt;
                                  &lt;Expander.Header&gt;
                                      &lt;StackPanel&gt;
                                          &lt;!-- label --&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;
  </code></pre>
  
  <h2>ViewModel</h2>
  
  <pre><code>public bool Expanded
  {
      get { return _expanded; }
      set { _expanded = value; OnPropertyChanged(); }
  }
  
  public ListCollectionView Items
  {
      get
      {
          return _items;
      }
      set
      {
          _items = value; OnPropertyChanged();
      }
  }
  
  // logic
  var items = new ListCollectionView(planninglist);
  items.SortDescriptions.Add(new items.GroupDescriptions.Add(new PropertyGroupDescription("AanZet"));
  items.IsLiveSorting = true;
  </code></pre>
  
  <h1>Update</h1>
  
  <p>Fix based on <a href="https://stackoverflow.com/questions/3771431/oneway-binding-for-togglebuttons-ischecked-property-in-wpf/3772335#3772335">SO answer</a> suggested in the comments by @XAMlMAX.</p>
  
  <pre><code>public class ExpanderBehavior
  {
      public static readonly DependencyProperty IsExpandedProperty =
    DependencyProperty.RegisterAttached("IsExpanded",
                                        typeof(bool),
                                        typeof(ExpanderBehavior),
                                        new PropertyMetadata(OnChanged));
  
      public static bool GetIsExpanded(DependencyObject obj)
      {
          return (bool)obj.GetValue(IsExpandedProperty);
      }
      public static void SetIsExpanded(DependencyObject obj, bool value)
      {
          obj.SetValue(IsExpandedProperty, value);
      }
  
      private static void OnChanged(DependencyObject o,
                                    DependencyPropertyChangedEventArgs args)
      {
          Expander tb = o as Expander;
          if (null != tb)
              tb.IsExpanded = (bool)args.NewValue;
      }
  }
  </code></pre>