Collapse a WPF or Silverlight panel on null

Add this style to app.xaml.

<Style x:Key="CollapseOnNull">
    <Style.Triggers>
        <DataTrigger Binding="{Binding}" Value="{x:Null}">
            <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

Set the style on a panel that is data bound to a selected item (ala Navigation Model).

<DockPanel DataContext="{Binding OpenProject}" Style="{StaticResource CollapseOnNull}">

Now the panel collapses when nothing is selected.

Leave a Reply

You must be logged in to post a comment.