WPF C# DataTrigger Binding to OnPropertyChanged

Multi tool use
WPF C# DataTrigger Binding to OnPropertyChanged
I'm trying to create a DataTrigger which changes the style of a border whenever a certain property is changed. I've created the property and I'm calling the PropertyChanged event and it works perfectly fine with other XAML components, but for some reason, it won't work with my DataTrigger.
XAML File:
<Style x:Key="InputParameterBorder" TargetType="Border" BasedOn="{StaticResource ParameterBorder}">
<Setter Property="Background" Value="{StaticResource GrayGradient}"/>
<Style.Triggers>
<!-- This changes input color -->
<DataTrigger Binding="{Binding Parameter, Converter={StaticResource IsNullConverter}}" Value="False">
<Setter Property="Background" Value="{StaticResource YellowGradient}" />
</DataTrigger>
</Style.Triggers>
</Style>
C# File:
private IInputParameter _parameter;
public event PropertyChangedEventHandler PropertyChanged;
public IInputParameter Parameter
{ get
{
return _parameter;
}
set
{
_parameter = value;
PropertyChanged(this, new PropertyChangedEventArgs("Parameter"));
}
}
EDIT: I changed InputParameter to Parameter in the Binding method, but it still doesn't work.
EDIT 2: Added XAML code with the implementation of InputParameterBorder.
<DataTemplate x:Key="InputParameterBox">
<Border Style="{StaticResource InputParameterBorder}"
AllowDrop="True" DragEnter="InputParameter_DragEnter" Drop="InputParameter_Drop"
MouseLeftButtonDown="InputParameter_MouseLeftButtonDown">
<Grid>
<TextBlock Text="{Binding Parameter.Type}"
Style="{StaticResource InputParameterTypeLabel}" />
<TextBlock Text="{Binding Parameter.Name}" Style="{StaticResource InputParameterNameLabel}" />
</Grid>
<!--TextBlock Text="{Binding Type, Converter={StaticResource WorkflowParameterTypeConverter}}" -->
</Border>
</DataTemplate>
And implementation of InputParameterBox:
<DataTemplate>
<ItemsControl ItemsSource="{Binding InputParameters}"
ItemTemplate="{StaticResource InputParameterBox}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" MaxWidth="200" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
Besides that, you should also check if PropertyChanged is null:
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Parameter)));
– Clemens
Jul 2 at 7:54
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Parameter)));
I also doubt that you actually need your IsNullConverter. You could use
Value="{x:Null}"
in the DataTrigger.– Clemens
Jul 2 at 7:56
Value="{x:Null}"
And the DataContext of the styled Border (or one of its parent elements) is set to an instance of the class with the Parameter property?
– Clemens
Jul 2 at 8:04
Could you show us how you apply this style in your xaml?
– XAMlMAX
Jul 2 at 8:41
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Your are binding to "InputParameter", but in your ViewModel ,you have a property named "Parameter". That could be your problem.
– Lupu Silviu
Jul 2 at 7:53