I'm using WPF with a TabControl. I've defined an ItemTemplate that sets a TextBlock for the title and a button to close the tab. I would like for the first tab to not have the close button visible. I've tried to set Visiblity of the button using Binding to a Public bool in my ViewModel and convert using the BooleanToVisibilityConverter but it looks like the ItemTemplate is being rendered when the TabControl is created and not when each Tab is added.
Here's my TabControl xaml (I've tried with and without the FallbackValue)
<TabControl x:Name="Items" Grid.Row="1" Grid.Column="0">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}" />
<Button x:Name="CloseTab" Content="X" Visibility="{Binding IsTabCloseButtonVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Hidden}"
cal:Message.Attach="DeactivateItem($dataContext, 'true')" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
In App.xaml I have the converter
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</ResourceDictionary>
</Application.Resources>
And in the ViewModel I have a public property
private bool _isTabCloseButtonVisible;
public bool IsTabCloseButtonVisible
{
get { return _isTabCloseButtonVisible; }
set
{
_isTabCloseButtonVisible = value;
NotifyOfPropertyChange(() => IsTabCloseButtonVisible);
}
}
I've tested that the property is being set by binding a Textblock to the IsTabCloseButtonVisible and it's changes from false to true.
Is it possible to acheive what I'm trying to do?