Parece que tienes que crear tu propio convertidor. Aquí un ejemplo sencillo para empezar:
public class ColorToSolidColorBrushValueConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
if (null == value) {
return null;
}
// For a more sophisticated converter, check also the targetType and react accordingly..
if (value is Color) {
Color color = (Color)value;
return new SolidColorBrush(color);
}
// You can support here more source types if you wish
// For the example I throw an exception
Type type = value.GetType();
throw new InvalidOperationException("Unsupported type ["+type.Name+"]");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
// If necessary, here you can convert back. Check if which brush it is (if its one),
// get its Color-value and return it.
throw new NotImplementedException();
}
}
Para usarlo, hacedlo saber en la sección de recursos.
<local:ColorToSolidColorBrushValueConverter x:Key="ColorToSolidColorBrush_ValueConverter"/>
Y el uso en la unión como un recurso estático:
Fill="{Binding Path=xyz,Converter={StaticResource ColorToSolidColorBrush_ValueConverter}}"
Yo no lo he probado. Haz un comentario si no está funcionando.
duplicado Posible : No hago http://stackoverflow.com/questions/372693/convert-string-to-brushes-brush-name-in-c –
creo que es un duplicadoQuiero convertir un objeto Color, no un valor de cadena como "Rojo". Y me gustaría implementarlo como un convertidor XAML, frente a realizar la conversión en el código C# detrás. – dthrasher