Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You bind the <code>Foreground</code> to a value on a <code>StaticResource</code> so all buttons will bind to this same value. </p> <p>You can either create a specific "ButtonForegroundConverter" or you can add the Brush property to the item level viewmodel that also has the <code>Outcome</code> property which you already bind to the <code>Content</code> of the button. Then the button xaml will look something like this:</p> <pre><code>&lt;Button ... Content="{Binding Outcome}" Foreground="{Binding OutcomeForegroundBrush}" ... /&gt; </code></pre> <p>If you are binding directly to an entity, then adding properties like that would not be a good idea, so the example above assumes you have a intermediate viewmodel or controller on which you could add properties like that.</p> <p>If you choose to use a converter it would look something like this:</p> <pre><code>&lt;Button ... Content="{Binding Outcome}" Foreground="{Binding OutcomeId, Converter={StaticResource OutcomeToForegroundConverter}}" ... /&gt; </code></pre> <p>And the converter:</p> <pre><code>namespace MyConverters { public sealed class OutcomeToColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // We must have a valid integer value, double check bindings if (value == null) { throw new ArgumentNullException("value", "Please make sure the value is not null."); } var OutcomeId = (int)value; if (OutcomeId == XXX) { return RED_BRUSH; } else { return BLUE_BRUSH; } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } static readonly SolidColorBrush RED_BRUSH = new SolidColorBrush(Colors.Red); static readonly SolidColorBrush BLUE_BRUSH = new SolidColorBrush(Colors.Blue); } } </code></pre> <p>Remember to declare the resource:</p> <pre><code>&lt;myconverters:OutcomeToForegroundConverter x:Key="OutcomeToForegroundConverter" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload