첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

/// <summary>
/// 색상→단색 브러시 변환자
/// </summary>
[ValueConversion(typeof(Color), typeof(Brush))]
public class ColorToSolidColorBrushConverter : IValueConverter
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo)

    /// <summary>
    /// 변환하기
    /// </summary>
    /// <param name="sourceValue">소스 값</param>
    /// <param name="targetType">타겟 타입</param>
    /// <param name="parameter">매개 변수</param>
    /// <param name="cultureInfo">문화 정보</param>
    /// <returns>변환 값</returns>
    public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
    {
        if(targetType != typeof(Brush))
        {
            return sourceValue;
        }

        if(sourceValue == null || sourceValue == DependencyProperty.UnsetValue || sourceValue.GetType() != typeof(Color))
        {
            return Brushes.Transparent;
        }

        Color color = (Color)sourceValue;

        return new SolidColorBrush(color);
    }

    #endregion
    #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo)

    /// <summary>
    /// 역변환하기
    /// </summary>
    /// <param name="sourceValue">소스 값</param>
    /// <param name="targetType">타겟 타입</param>
    /// <param name="parameter">매개 변수</param>
    /// <param name="cultureInfo">문화 정보</param>
    /// <returns>역변환 값</returns>
    public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
    {
        throw new NotImplementedException();
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요