■ IMultiValueConverter 인터페이스 사용하기

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

FormattedTextMultiValueConverter.cs

 

using System;

using System.Globalization;

using System.Windows.Data;

 

/// <summary>

/// 포맷 텍스트 멀티 값 변환자

/// </summary>

public class FormattedTextMultiValueConverter : IMultiValueConverter

{

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

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

 

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

 

    /// <summary>

    /// 변환하기

    /// </summary>

    /// <param name="sourceValueArray">소스 값 배열</param>

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

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

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

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

    public object Convert(object[] sourceValueArray, Type targetType, object parameter, CultureInfo cultureInfo)

    {

        return String.Format((string)parameter, sourceValueArray);

    }

 

    #endregion

 

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

 

    /// <summary>

    /// 역변환하기

    /// </summary>

    /// <param name="sourceValue">소스 값</param>

    /// <param name="targetTypeArray">타겟 타입 배열</param>

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

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

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

    public object[] ConvertBack(object sourceValue, Type[] targetTypeArray, object parameter, CultureInfo cultureInfo)

    {

        return null;

    }

 

    #endregion

}

 

TestWindow.xaml

 

<Window

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:s="clr-namespace:System;assembly=mscorlib"

    xmlns:src="clr-namespace:WpfApplication1"

    Title="환경 정보">

    <Window.Resources>

        <src:FormattedTextMultiValueConverter x:Key="FormattedTextMultiValueConverterKey" />

    </Window.Resources>

    <TextBlock>

        <TextBlock.Text>

            <MultiBinding

                Converter="{StaticResource FormattedTextMultiValueConverterKey}"

                ConverterParameter=

"Operating System Version: {0}

&#x000A;.NET Version: {1}

&#x000A;Machine Name: {2}

&#x000A;User Name: {3}

&#x000A;User Domain Name: {4}

&#x000A;System Directory: {5}

&#x000A;Current Directory: {6}

&#x000A;Command Line: {7}">

                <Binding Source="{x:Static s:Environment.OSVersion       }" />

                <Binding Source="{x:Static s:Environment.Version         }" />

                <Binding Source="{x:Static s:Environment.MachineName     }" />

                <Binding Source="{x:Static s:Environment.UserName        }" />

                <Binding Source="{x:Static s:Environment.UserDomainName }" />

                <Binding Source="{x:Static s:Environment.SystemDirectory }" />

                <Binding Source="{x:Static s:Environment.CurrentDirectory}" />

                <Binding Source="{x:Static s:Environment.CommandLine     }" />

            </MultiBinding>

        </TextBlock.Text>

    </TextBlock>

</Window>

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

Posted by 사용자 icodebroker
TAG