Is there any tri开发者_StackOverflow中文版gger 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?
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.
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.
精彩评论