meine Sys/Db admin & Developper Notitzen - wer Rechtschreibfehler findet darf sie behalten ... my Sys/Db Admin and developper notes - I don't care about typos
Thursday, June 21, 2018
Wpf Converter with DependendyProperty
public class ColorStringToBrushConverter : DependencyObject, IValueConverter
{
public static readonly DependencyProperty DefaultBrush_PROPERTY = DependencyProperty.Register("DefaultBrush", typeof(Brush), typeof(ColorStringToBrushConverter));
public Brush DefaultBrush
{
get => (Brush)GetValue(DefaultBrush_PROPERTY);
set => SetValue(DefaultBrush_PROPERTY, value);
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var brush = DefaultBrush;
string colorString = value as string;
if (string.IsNullOrEmpty(colorString)) //use parameter if value not set
colorString = parameter as string;
if (!string.IsNullOrEmpty(colorString))
{
var colorObject = ColorConverter.ConvertFromString(colorString);
if (null != colorObject)
{
var color = (Color)colorObject;
brush = new SolidColorBrush(color);
}
}
return brush;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment