views:

36

answers:

2

Is there any trigger I can create to see if a Tabcontrol has only one TabItem. In these cases I actually have a TabItem collection in the codebehind wich I could possibly use a count method on.

In the case of only one tab I wan't to hide the TabPanel. Can I just call visibility=collapse on it?

+1  A: 

If you are using an ObservableCollection in the code behind, you could use the CollectionChanged event, and check the size of the collection then. About the TabPanel's visibility I don't know but you can try it.

jpsstavares
+1  A: 

In the control template of the TabItems I put:

<ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl, AncestorLevel=1}}" Value="1">
             <Setter Property="Visibility" Value="Collapsed" />
        </DataTrigger>
</ControlTemplate.Triggers>

and it works like a charm.

Ingó Vals