title: Can you bind the visibility of a GroupBox to the visibility of it's children?
body: <p>I have an issue trying to get a GroupBox to collapse. I want a GroupBox which will collapse if all it's children are collapsed. </p>
  
  <p>I have managed to achieve this using a multibinding to the properties, as shown below. </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;StackPanel&gt;
      &lt;GroupBox&gt;
        &lt;GroupBox.Visibility&gt;
          &lt;MultiBinding 
            Converter="{StaticResource multiBoolOrToVis}"
            ConverterParameter="{x:Static Visibility.Collapsed}"
          &gt;
            &lt;Binding Path="a_visible"/&gt;
            &lt;Binding Path="b_visible"/&gt;
          &lt;/MultiBinding&gt;
        &lt;/GroupBox.Visibility&gt;
          &lt;GroupBox.Header&gt;
          &lt;Label Content="GroupBox"/&gt;
        &lt;/GroupBox.Header&gt;
        &lt;StackPanel&gt;
          &lt;Label 
            Content="A"
            Visibility="{Binding Path=a_visible, Converter={StaticResource boolToVis}}"
          /&gt;
          &lt;Label 
            Content="B"
            Visibility="{Binding Path=b_visible, Converter={StaticResource boolToVis}}"
          /&gt;
        &lt;/StackPanel&gt;
      &lt;/GroupBox&gt;
      &lt;Grid&gt;
        &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*"/&gt;
          &lt;ColumnDefinition Width="*"/&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;CheckBox 
          Content="A Visible"
          Grid.Column="0"
          Grid.Row="1"
          IsChecked="{Binding Path=a_visible, Mode=TwoWay}"
        /&gt;
        &lt;CheckBox 
          Content="B Visible"
          Grid.Column="1"
          Grid.Row="1"
          IsChecked="{Binding Path=b_visible, Mode=TwoWay}"
        /&gt;
      &lt;/Grid&gt;
    &lt;/StackPanel&gt;
  </code></pre>
  
  <p>The problem with this is we want to be able to do this multiple times and not worry about leaving off a binding. So my question is there any way of doing this generically, preferably in a style. Another requirement is that it has to be in xaml not code behind.</p>
  
  <p>So my ideal answer would be a style so I could the following in my xaml.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;StackPanel&gt;
      &lt;GroupBox Style="ChildrenVisibilityStyle"&gt;
          &lt;GroupBox.Header&gt;
          &lt;Label Content="GroupBox"/&gt;
        &lt;/GroupBox.Header&gt;
        &lt;StackPanel&gt;
          &lt;Label 
            Content="A"
            Visibility="{Binding Path=a_visible, Converter={StaticResource boolToVis}}"
          /&gt;
          &lt;Label 
            Content="B"
            Visibility="{Binding Path=b_visible, Converter={StaticResource boolToVis}}"
          /&gt;
        &lt;/StackPanel&gt;
      &lt;/GroupBox&gt;
      &lt;Grid&gt;
        &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*"/&gt;
          &lt;ColumnDefinition Width="*"/&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;CheckBox 
          Content="A Visible"
          Grid.Column="0"
          Grid.Row="1"
          IsChecked="{Binding Path=a_visible, Mode=TwoWay}"
        /&gt;
        &lt;CheckBox 
          Content="B Visible"
          Grid.Column="1"
          Grid.Row="1"
          IsChecked="{Binding Path=b_visible, Mode=TwoWay}"
        /&gt;
      &lt;/Grid&gt;
    &lt;/StackPanel&gt;
  </code></pre>
  
  <p>I have looked at these questions and they lead me to think that this isn't possible; <a href="https://stackoverflow.com/questions/3046262/wpf-binding-to-observablecollection-in-controltemplate-is-not-updated">binding in controltemplate</a>, <a href="https://stackoverflow.com/questions/569144/bind-stackpanel-visibility-to-the-visibility-property-of-its-children">stackpanel visibility</a>, <a href="https://stackoverflow.com/questions/9921969/how-can-i-bind-a-border-visibility-to-the-visibility-of-containing-children-obje">border visibility</a>. </p>
  
  <p>Sorry if this has been answered before. Thanks in advance for any answers/comments.</p>