|
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Data;
- using System.Windows.Media;
-
- namespace BeDesignerSCADA.Converters
- {
- [ValueConversion(typeof(string), typeof(System.Drawing.Color))]
- public class ColorToStringConverter : IValueConverter
- {
- static ColorToStringConverter()
- {
- Instance = new ColorToStringConverter();
- }
-
- public static ColorToStringConverter Instance
- {
- get;
- private set;
- }
-
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- if (value is System.Windows.Media.LinearGradientBrush)
- {
- return value;// == null ? null : ((System.Windows.Media.LinearGradientBrush)value);
- }
- else if (value is System.Windows.Media.ImageBrush)
- {
- return value;// == null ? null : ((System.Windows.Media.ImageBrush)value);
- }
- else
- return value==null?null:((SolidColorBrush)value).Color;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return value == null ? null : new SolidColorBrush((System.Windows.Media.Color)value);
- }
- }
- }
|