开发者

WPF: trigger to check if TabControl has only 1 tab!

开发者 https://www.devze.com 2023-01-07 07:21 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消