If i understand you correctly, you are looking for a way to bind the Value
of the DataTrigger
to your MaxTagCount
property, which isn't possible due to the fact that Value
isn't a dependency property.
The most common workaround that is to pass both the MaxTagCount
property and the Count
property to a MultiValueConverter
, the converter will compare those two values and return true or false. The role of the DataTrigger
now will be to check the value returned by the converter so:
First, define a basic converter that compares two values like so:
public class CompareValuesConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values?[0].Equals(values[1]);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Second, update your DataTrigger
to check the returned value of the converter, and pass your values to the converter, and set your style accordingly:
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding >
<MultiBinding.Converter>
<local:CompareValuesConverter/>
</MultiBinding.Converter>
<Binding Path="Count" />
<Binding Path="DataContext.MaxTagCount" ElementName="Main"/>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="Green"/>
</DataTrigger>
Notice that i am using an ElementName
binding to get the MaxTagCount
value since it is (most likely) defined on the global UI DataContext
(in this case the main Window is Named Main
), you could also use a RelativeSource
binding.