■ IValueConverter 인터페이스 : FrameworkPropertyMetadata → FrameworkPropertyMetadataOptions 값 변환자 만들기

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

using System;

using System.Globalization;

using System.Windows;

using System.Windows.Data;

 

/// <summary>

/// FrameworkPropertyMetadata → FrameworkPropertyMetadataOptions 값 변환자

/// </summary>

public class FrameworkPropertyMetadataToFrameworkPropertyMetadataOptionsValueConverter : IValueConverter

{

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

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

 

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

 

    /// <summary>

    /// 변환하기

    /// </summary>

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

    /// <param name="type">타입</param>

    /// <param name="parameter">파라미터</param>

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

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

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

    {

        FrameworkPropertyMetadata frameworkPropertyMetadata = value as FrameworkPropertyMetadata;

 

        FrameworkPropertyMetadataOptions frameworkPropertyMetadataOptions = 0;

 

        if(frameworkPropertyMetadata == null)

        {

            return null;

        }

 

        if(frameworkPropertyMetadata.AffectsMeasure)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.AffectsMeasure;

        }

 

        if(frameworkPropertyMetadata.AffectsArrange)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.AffectsArrange;

        }

 

        if(frameworkPropertyMetadata.AffectsParentMeasure)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.AffectsParentMeasure;

        }

 

        if(frameworkPropertyMetadata.AffectsParentArrange)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.AffectsParentArrange;

        }

 

        if(frameworkPropertyMetadata.AffectsRender)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.AffectsRender;

        }

 

        if(frameworkPropertyMetadata.Inherits)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.Inherits;

        }

 

        if(frameworkPropertyMetadata.OverridesInheritanceBehavior)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.OverridesInheritanceBehavior;

        }

 

        if(frameworkPropertyMetadata.IsNotDataBindable)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.NotDataBindable;

        }

 

        if(frameworkPropertyMetadata.BindsTwoWayByDefault)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.BindsTwoWayByDefault;

        }

 

        if(frameworkPropertyMetadata.Journal)

        {

            frameworkPropertyMetadataOptions |= FrameworkPropertyMetadataOptions.Journal;

        }

 

        return frameworkPropertyMetadataOptions;

    }

 

    #endregion

 

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

 

    /// <summary>

    /// 역변환하기

    /// </summary>

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

    /// <param name="type">타입</param>

    /// <param name="parameter">파라미터</param>

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

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

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

    {

        return new FrameworkPropertyMetadata(null, (FrameworkPropertyMetadataOptions)value);

    }

 

    #endregion

}

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요