Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I selectively set the "Visibility" of a TabItem via DataBinding/Triggers

I have a tab page that should be hidden if a property (BlahType) is set to 1 and shown if set to 0. This is what I WANT to do:

<TabItem Header="Blah">
    <TabItem.Triggers>
        <DataTrigger Binding="{Binding BlahType}" Value="0">
            <Setter Property="TabItem.Visibility" Value="Hidden" />
        </DataTrigger>
    </TabItem.Triggers>
</TabItem>

The problem is, I get this error:

"Triggers collection members must be of type EventTrigger"

If you Google that error, you'll see that Dr. WPF explains the error. Is there a clean way to do what I'm trying to achieve here?

like image 319
Timothy Khouri Avatar asked Nov 19 '08 15:11

Timothy Khouri


1 Answers

I believe that the Triggers collection of a control only currently supports EventTriggers. If you would like to use a DataTrigger simply place it inside a style, for your example:

<TabItem Header="Blah">
    <TabItem.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding BlahType}" Value="0">
                    <Setter Property="TabItem.Visibility" Value="Hidden" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TabItem.Style>
</TabItem>
like image 152
David Padbury Avatar answered Sep 28 '22 01:09

David Padbury