开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜