添加项目文件。
This commit is contained in:
33
WPFWCSDemo/Common/Converters/ColorToBrushConverter.cs
Normal file
33
WPFWCSDemo/Common/Converters/ColorToBrushConverter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace WPFWCSDemo.Common.Converters
|
||||
{
|
||||
[ValueConversion(typeof(Color), typeof(Brush))]
|
||||
public class ColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
{
|
||||
return brush.Color;
|
||||
}
|
||||
return default(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user