title: Modify expander header children when expanded
body: <p>I can't figure out how to do it in XAML.  I came up with workarounds that use Expanded/Collapsed events, but they just don't feel right.</p>
  
  <p>I have a DataGrid, with groups, that are templated as expanders.  I have a button inside expander, that's hidden by default, and only needs to be shown when an expander is expanded.  </p>
  
  <pre><code>&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="True"&gt;
                          &lt;Expander.Header&gt;
                              &lt;StackPanel Orientation="Horizontal"&gt;
                                  &lt;TextBlock Text="Some Text"/&gt;
                                  &lt;Button Name="MyButton" Visibility="Collapsed" Content="Add All"/&gt;                                                    
                              &lt;/StackPanel&gt;
                          &lt;/Expander.Header&gt;
                          &lt;Expander.Content&gt;
                              &lt;ItemsPresenter /&gt;
                          &lt;/Expander.Content&gt;
                      &lt;/Expander&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  &lt;/GroupStyle.ContainerStyle&gt;
  </code></pre>
  
  <p>So basically the code in question is right in the middle:</p>
  
  <pre><code>&lt;Expander IsExpanded="True"&gt;
      &lt;Expander.Header&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;TextBlock Text="Some Text"/&gt;
              &lt;Button Name="MyButton" Visibility="Collapsed" Content="Add All"/&gt;                                                    
          &lt;/StackPanel&gt;
      &lt;/Expander.Header&gt;
      &lt;Expander.Content&gt;
          &lt;ItemsPresenter /&gt;
      &lt;/Expander.Content&gt;
  &lt;/Expander&gt;
  </code></pre>
  
  <p>I'm trying to set Visibility of the Button to false, when the expander is expanded.  I tried using a trigger like the following:</p>
  
  <pre><code>&lt;Expander.Style&gt;
      &lt;Style TargetType="Expander"&gt;
          &lt;Style.Triggers&gt;
              &lt;DataTrigger Binding="{Binding IsExpanded, RelativeSource={RelativeSource Self}}" Value="False"&gt;
                  &lt;Setter TargetProperty="MyButton" Property="Visibility" Value="Visible" /&gt;
              &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/Expander.Style&gt;
  </code></pre>
  
  <p>, but the compiler doesn't accept it, because it can't find MyButton (I'm guessing because it's inside a header).  Any ideas on how I can get this to work?</p>