Reputation: 407
We are working on setting collor setting stored in a JSON file for the user. But when I bind to the color in my XAML it doesn't work.
Upvotes: 0
Views: 64
Reputation: 1236
You cannot bind to a color directly to use. You have to use a converter to get a SolidColorBrush
. You can do it with this converter:
public class ColorToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (!(value is Windows.UI.Color)) return null;
return new SolidColorBrush((Windows.UI.Color)value);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return null;
}
}
More on using Converters, see MSDN
Upvotes: 2
Reputation: 8039
You need to convert that color value to a SolidColorBrush
in order to bind it to your controls.
Best way would be to write a converter that converts from your JSON value to a SolidColorBrush.
If you show some of your code, and what exactly the problem is we might be able to give more specific advice.
Upvotes: 2