Blog categories

Comments

[WPF] 두 개 이상의 Command Parameter 넘기기

[WPF] 두 개 이상의 Command Parameter 넘기기

XAML

<Button x:Name="bt_show" Grid.Row="5" Grid.Column="1" Content="조회" Margin="10" Command="{Binding GetCodeListByMarketCommand}">
    <Button.CommandParameter>
        <MultiBinding Converter="{StaticResource ParamToStringAxKHConverter}">
            <Binding ElementName="cb_market_type" Path="SelectedValue" />
            <Binding ElementName="axKHOpenAPI" />
        </MultiBinding>
    </Button.CommandParameter>
</Button>

Converter

public class StringAxKH
{
    public string _str;
    public AxKHOpenAPI _axKHOpenAPI;

    public StringAxKH(string str, AxKHOpenAPI axKHOpenAPI)
    {
        _str = str;
        _axKHOpenAPI = axKHOpenAPI;
    }

    public StringAxKH(object str, object axKHOpenAPI)
    {
        _str = str as string;
        _axKHOpenAPI = axKHOpenAPI as AxKHOpenAPI;
    }
}

public class ParamToStringAxKHConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return new StringAxKH(values[0], values[1]);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Command Execution Logic

#region [Command] GetCodeListByMarketCommand
public RelayCommand<Converter.StringAxKH> GetCodeListByMarketCommand
{
    get
    {
        return _getCodeListByMarketCommand
            ?? (_getCodeListByMarketCommand = new RelayCommand<Converter.StringAxKH>(
                    (objStringAxKH) =>
                    {
                        AxKHOpenAPI axKHOpenAPI = objStringAxKH._axKHOpenAPI;
                        string sMarket = objStringAxKH._str;

                        CodeList = new Kiwoom.KiwoomHelper(axKHOpenAPI).GetCodeListByMarket(sMarket);
                    }
                ));
    }
}
#endregion

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

div#stuning-header .dfd-stuning-header-bg-container {background-color: #3f3f3f;background-size: cover;background-position: top center;background-attachment: initial;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 350px;}