I have a tab control bound to an observablecollection for dynamic tabs as follows:
<TabControl ItemsSource="{Binding AllTabs}" SelectedIndex="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TabControl.ItemTemplate>
<DataTemplate>
<!--.............. -->
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate DataType="{x:Type vm:TabViewModel}">
<c:MyTabItem/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
So, the tab headers and contents are defined dynamically and assigned as the observable collection changes. Now, I would like to hide some tabs without deleting them in the collection behind – in order to keep the data should the tab reopen.
Ideally, each chat tab viewmodel has a IsVisible property that is set to true by default. However, where do I bind such a property to in order to make a tab item collapse?
If you can modify your
vm:TabViewModelI should change your IsVisible to a Visibility property and use the following ContentTemplate:Else you could use a converter to change the boolean IsVisible to an Visibility enum:
Inculde the namespace in your xaml (your root element, Window in this example):
And in your resources:
And finaly the binding:
I think thats it 🙂
Edit: Ow and change the ConverterParameter to Visibility.Collapsed to Visibility.Hidden for hidden 😉