I have declared my dependency properties as follows
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));
In XAML, I want to have a trigger thats triggers the style based on the value of my dependency property. In this case bold if CanSave
is true
<Style x:Key="CanSaveIndicatorHeader">
<Style.Triggers>
<Trigger Property="{Binding CanSave}" Value="True">
<Setter Property="TextBlock.FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
i am getting the error
A 'Binding' cannot be set on the 'Property' property of type 'Trigger'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
I am probably doing something wrong. Can someone correct me?
UPDATE: In response to @Bryan Watts
Ok, so I did something like
<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>
Then i discovered that CanSave is never set to true, then I did
<TextBox ... Text="{Binding Path=Content, UpdateSourceTrigger=PropertyChanged}" />
as CanSave is set to true when Content changes
public string Content
{
...
set
{
if ((bool)GetValue(CanSaveProperty) == false)
{
SetValue(CanSaveProperty, true);
RaisePropertyChanged("CanSave");
}
_content = value;
}
}
But it seems
<Trigger Property="vm:EditorTabViewModel.CanSave" Value="true">
nv happens as the font is never bold. It seems WPF doesn't detect the change?