So i'm having some binding issues ATM with my "GroupColour" property on my ObjA class. I also have a CurrentState variable, which, based on its value, returns a Brush (this is done in the converter below).
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace UIChemicalMelt
{
public class StateToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
switch (value)
{
case State.INACTIVE:
return Utilities.ResourceDictionary["HoverOverColourInactive"] as Brush;
case State.ACTIVE:
return Utilities.ResourceDictionary["HoverOverColourActive"] as Brush;
case State.ACTIVE_GROUP_SET:
return Utilities.ResourceDictionary["BackgroundBasedOnGroupColour"] as Brush;
case State.HIGHLIGHTED:
return Utilities.ResourceDictionary["HighlightThemeColour"] as Brush;
case State.PROCESSING:
return Utilities.ResourceDictionary["ProcessingWellColour"] as Brush;
default:
return Brushes.Transparent.Color;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
It is used in my ControlTemplate Triggers of my buttons that I create in my View XAML
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Background" Value="{Binding CurrentState, Converter={StaticResource StateToColorConverter}}"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Background" Value="{Binding CurrentState, Converter={StaticResource StateToColorConverter}}"/>
</Trigger>
</ControlTemplate.Triggers>
It all seems to work fine, but I get a XAML error...
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=GroupColour; DataItem=null; target element is 'SolidColorBrush' (HashCode=46663997); target property is 'Color' (type 'Color')
I don't know why tbh..
SolidColorBrushinstead ofBrush. - Gaurang DaveCurrentStateproperty defined and what's theDataContextof theButton? - mm8GroupColourproperty instead which is aSolidColorBrush.... bit annoying though since the converter returns aSolidColorBrush..... - uaswpf