■ IValueConverter 인터페이스 : 실수↔바이트 값 변환자 만들기

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

using System;
using System.Globalization;
using System.Windows.Data;

/// <summary>
///
배정도 실수↔바이트 값 변환자
/// </summary>
[ValueConversion(typeof(double), typeof(byte))]
public class DoubleToByteValueConverter : 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">CultureInfo</param>
   /// <returns>변환 값</returns>
   public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
   {
       
return (byte)(double)sourceValue;
   }

   #endregion

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

   
/// <summary>
   /// 역변환하기
   /// </summary>
   /// <param name="sourceValue">소스 값</param>
   /// <param name="targetType">타겟 타입</param>
   /// <param name="parameter">파라미터</param>
   /// <param name="cultureInfo">CultureInfo</param>
   /// <returns>역변환 값</returns>
   public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
   {
       
return (double)sourceValue;
   }

   #endregion
}
----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG