Search code examples
c#wpfxamllogicdatatrigger

Using logic (smaller than, equal to, bigger than) in XAML datatrigger


I'm not that good with XAML but I want to have a data-trigger which is bound to a variable on my page.cs which is a double.

If the double is bigger than 0.25, I want it to trigger. If it's 0.5 I want another one to trigger.

How would you do this kind of stuff? Any pages to read up on this would be awesome


Solution

  • You can use converters implementing IValueConverter interface which convert double to bool, based on a value of converter parameter.

    For example a converter DoubleMoreThanConverter would accept double value, double converter parameter and return bool in Convert method. You can set Converter and ConverterParameter properties of a binding you put into DataTrigger.