wpf databind IsVisible to TabControl.SelectedItem != null

data-binding, visibility, wpf

Solution

You can do it without a converter by using a style and trigger:

<StackPanel>
    <StackPanel.Style>
        <Style TargetType="{x:Type StackPanel}">
            <Setter Property="Visibility" Value="Visible" />
            <Style.Triggers>
                <DataTrigger
                    Binding="{Binding SelectedItem,ElementName=tabControl1}" 
                    Value="{x:Null}">
                    <Setter Property="Visibility" Value="Hidden" />
                </DataTrigger>
            <Style.Triggers>
        </Style>
    </StackPanel.Style>
</StackPanel>

This example shows the StackPanel by default, but then hides it when the SelectedItem on tabControl1 is null.

Problem

I have a `StackPanel` which I want to make visible only when `SomeTabControl.SelectedItem != null`. How do I do this in WPF binding?

Original source