At the first glance the task looks similar to WPF TextBlock Negative Number In Red
In my case I have to display in an ItemsControl
a collection of Points. Each Point has several properties of type NumericValue that is ultimately a wrapper around Nullable<double>
.
public class Point
{
NumericValue Proposal { get; set; }
NumericValue Accepted { get; set; }
NumericValue Approved { get; set; }
... etc.
}
I display all those properties of a Point as TextBoxes. The class NumericValue has the property IsNegative and I want the Foreground of the corresponding Textbox to be red if IsNegative=True.
However, I'd prefer not to define this rule in a style for each individual TextBox but to make a single style with DataTrigger bound to IsNegative.
The simplified XAML looks like the one below.
<ItemsControl ItemsSource="{Binding Path=Points}">
...
<TextBox Text="{Binding Path=Data.Proposal.Value}" ... />
<TextBox Text="{Binding Path=Data.Accepted.Value}" ... />
...
</ItemsControl>
Please help me with the binding definition for the DataTrigger of that single style.
Data
property is the point the binding would be{Binding Data.IsNegative}
(which here is equivalent to{Binding Path=Data.IsNegative}
). If a binding does not do anything you should try to debug it. – H.B.