Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf databind IsVisible to TabControl.SelectedItem != null

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

like image 884
Peter Morris Avatar asked Jul 21 '09 10:07

Peter Morris


1 Answers

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.

like image 147
Matt Hamilton Avatar answered Oct 02 '22 19:10

Matt Hamilton