I don't know if I am using dependency properties right, but it seems my View never updates. I have a style trigger to change the styles of my elements. It seems the code runs, but the view is not updated. This is my 1st time using a Dependency Property & I maybe using it wrong
C#
public bool CanSave
{
get { return (bool)GetValue(CanSaveProperty); }
set { SetValue(CanSaveProperty, value); }
}
public static readonly DependencyProperty CanSaveProperty =
DependencyProperty.Register("CanSave", typeof(bool), typeof(EditorTabViewModel), new PropertyMetadata(false));
public string Content
{
get { return _content; }
set
{
if ((bool)GetValue(CanSaveProperty) == false)
{
SetValue(CanSaveProperty, true);
RaisePropertyChanged("CanSave");
}
_content = value;
}
}
XAML
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style x:Key="CanSaveIndicatorHeader">
<Style.Triggers>
<Trigger Property="vm:EditorTabViewModel.CanSave" Value="true">
<Setter Property="TextBlock.FontWeight" Value="Bold" />
</Trigger>
<Trigger Property="vm:EditorTabViewModel.CanSave" Value="false">
<Setter Property="TextBlock.Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBlock Text="{Binding TabTitle}" Padding="0,0,10,0" Style="{StaticResource CanSaveIndicatorHeader}" />
<Button Content="X" Command="{Binding CloseCommand}" FontSize="10" FontWeight="Bold" Padding="3,0">
</Button>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
The TextBlock is always red nv bold
UPDATE: Prefixing the tab header with *
<StackPanel Orientation="Horizontal">
<TextBlock Text="* " x:Name="TabTitleSaveIndicator" Visibility="Collapsed" />
<TextBlock Text="{Binding TabTitle}" x:Name="TabTitle" Padding="0,0,10,0" />
<Button Content="X" Command="{Binding CloseCommand}" FontSize="10" FontWeight="Bold" Padding="3,0">
</Button>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding CanSave}" Value="True">
<Setter TargetName="TabTitle" Property="FontWeight" Value="Bold" />
<Setter TargetName="TabTitleSaveIndicator" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>