■ IValueConverter 인터페이스 : 일자→일자 문자열 값 변환자 만들기

----------------------------------------------------------------------------------------------------

using System;

using System.Globalization;

using System.Windows.Data;

 

/// <summary>

/// 일시→문자열 값 변환자

/// </summary>

public class DateTimeToStringValueConverter : IValueConverter

{

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method

    ////////////////////////////////////////////////////////////////////////////////////////// Public

 

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

 

    /// <summary>

    /// 변환하기

    /// </summary>

    /// <param name="value"></param>

    /// <param name="targetType">타겟 타입</param>

    /// <param name="parameter">매개 변수</param>

    /// <param name="cultureInfo">CultureInfo 객체</param>

    /// <returns>변환 값</returns>

    public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)

    {

        DateTime? dateTime = (DateTime?)value;

        string    format  = parameter as string;

 

        if(dateTime.HasValue)

        {

            if(string.IsNullOrEmpty(format))

            {

                return dateTime.Value.ToString();

            }

            else

            {

                return dateTime.Value.ToString(format, cultureInfo);

            }

        }

        else

        {

            return string.Empty;

        }

    }

 

    #endregion

 

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

 

    /// <summary>

    /// 역변환하기

    /// </summary>

    /// <param name="value"></param>

    /// <param name="targetType">타겟 타입</param>

    /// <param name="parameter">매개 변수</param>

    /// <param name="cultureInfo">CultureInfo 객체</param>

    /// <returns>역변환 값</returns>

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)

    {

        throw new NotImplementedException();

    }

 

    #endregion

}

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요