首页 > 其他分享 >WPF CommandParameter 传递多个参数的方法

WPF CommandParameter 传递多个参数的方法

时间:2022-10-31 09:56:58浏览次数:65  
标签:CommandParameter culture object System IMultiValueConverter values 参数 WPF public

1、新建一个按钮内容如下

<Button Name="btnOK" 
                            Content="确定" 
                            Height="20"
                            Width="50"
                            Background="#00FF99"  
                            HorizontalAlignment="Left" 
                            Margin="442,30,0,0" 
                            VerticalAlignment="Top" 
                            Command="{Binding ConfirmCommand}"
                            >
                        <Button.CommandParameter>
                            <MultiBinding Converter="{ StaticResource ResourceKey=objectConverter}" Mode="TwoWay">
                                <MultiBinding.Bindings>
                                    <Binding ElementName="dataPickerInts" Path="Datas"/>
                                    <Binding ElementName="dataPickerBytes" Path="Datas"/>
                                </MultiBinding.Bindings>
                            </MultiBinding>
                        </Button.CommandParameter>
                    </Button>
2、新建一个类继承:IMultiValueConverter
  public class ObjectConvert : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public static object ConverterObject;       

        public object Convert(object[] values, Type targetType,
          object parameter, System.Globalization.CultureInfo culture)
        {
            ConverterObject = values;
            string str = values.GetType().ToString();   
            return values.ToArray();
        }

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

        #endregion
    }
3、最后在主窗口引入
<Window.Resources>
        <local:ObjectConvert x:Key="objectConverter"/>
    </Window.Resources>

标签:CommandParameter,culture,object,System,IMultiValueConverter,values,参数,WPF,public
From: https://www.cnblogs.com/lisghxfdfgh/p/16843264.html

相关文章