zoukankan      html  css  js  c++  java
  • WPF – pass multiple parameters to a Command

    public class SendCommand : ICommand
    {
        public void Execute(object parameter)
        {
            var labels = ((object[]) parameter).OfType<Label>();
        }
     
        public bool CanExecute(object parameter)
        {
            return true;
        }
     
        public event EventHandler CanExecuteChanged = delegate {};
    }
     
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            SendCommand = new SendCommand();           
        }
     
        public ICommand SendCommand { get; set; }
    }
     
    public class PassThroughConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return values.ToArray();
        }
     
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

     

    <Window x:Class="WpfApplication5.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfApplication5="clr-namespace:WpfApplication5"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <wpfApplication5:PassThroughConverter x:Key="PassthroughConverter" />
        </Window.Resources>
        <Grid>
          <StackPanel>
            <Label Name="Greeting">Hello</Label>
            <Label Name="Farewell">Goodbye</Label>
            <Button Command="{Binding SendCommand}">Hit me
              <Button.CommandParameter>
                <MultiBinding Converter="{StaticResource PassthroughConverter}">
                  <Binding Path="." ElementName="Greeting"></Binding>
                  <Binding Path="." ElementName="Farewell"></Binding>             
                </MultiBinding>
              </Button.CommandParameter>
            </Button>
          </StackPanel>
        </Grid>
    </Window>
  • 相关阅读:
    手机储存卡被写保护怎样删掉
    EXT.NET复杂布局(四)——系统首页设计(下)
    排序算法——选择排序
    NET 程序员十种必备工具 目录
    三种序列化体式格式
    Limitations of SharePoint Web Services
    How to: Update List Items
    哄骗JQuery直接调用asp.net后台办法
    jquery Dialog 弹出窗插件
    EXT.NET高效开发(四)——实用技巧
  • 原文地址:https://www.cnblogs.com/xpvincent/p/4140200.html
Copyright © 2011-2022 走看看