I'd do this with a MultiBinding
and a multi-value converter:
Converter:
public class DateEqualsConverter : IMultiValueConverter
{
public object Convert(object[] values,
Type targetType,
object parameter,
CultureInfo culture)
{
return System.Convert.ToDateTime(values[0])
.Equals(System.Convert.ToDateTime(values[1]));
}
public object[] ConvertBack(object value,
Type[] targetTypes,
object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
Window resources (maybe this is UserControl.Resources
instead; you didn't say):
<Window.Resources>
<local:DateEqualsConverter x:Key="DateEquals" />
</Window.Resources>
And here's the DataTrigger
in the Style
. I don't know the name of the viewmodel property you're comparing SDate
to, so I just called it GreenDate
.
OTOH I'm guessing that "The variable is already part of my datacontent" means that the property is already defined in your viewmodel, and your viewmodel is your DataContext
. That may be one guess too many. Let me know.
<DataTrigger
Value="True"
>
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource DateEquals}">
<MultiBinding.Bindings>
<Binding Path="SDate" />
<Binding Path="GreenDate" />
</MultiBinding.Bindings>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Background" Value="Green" />
</DataTrigger>