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>
WPF – pass multiple parameters to a Command的更多相关文章
- How to pass multiple parameters in PowerShell invoke-restmethod
Link: http://www.tagwith.com/question_322855_how-to-pass-parameters-in-powershell-invoke-restmethod- ...
- Can't bind multiple parameters ('header' and 'parameters') to the request's content.
2019-01-23 15:46:29.012+08:00 ERROR [6]: System.InvalidOperationException: Can't bind multiple param ...
- How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
Snesh Prajapati, 8 Dec 2014 http://www.codeproject.com/Articles/717941/How-to-Choose-the-Best-Way-to ...
- WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法
原文:WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法 问题描述 今天发现如果我想在一个TextBlock弄一个右键菜单,并且使用Command绑定,结果发 ...
- EXEC sp_executesql with multiple parameters
传递多个参数 https://stackoverflow.com/questions/28481189/exec-sp-executesql-with-multiple-parameters http ...
- WPF: 使用CommandManager.InvalidateRequerySuggested手动更新Command状态
WPF判断命令(Command)是否能够执行是通过ICommand.CanExecute事件,在实际程序中路由命令一般是通过CommandBinding来使命令得到实际操作代码,但是这个CanExec ...
- WPF Datagrid multiple selecteditems in MVVM
I can assure you: SelectedItems is indeed bindable as a XAML CommandParameter After a lot of digging ...
- Part 89 to 91 Talking about pass the parameters in thread
Part 89 ParameterizedThreadStart delegate Use ParameterizedThreadStart delegate to pass data to th ...
- JNI: Passing multiple parameters in the function signature for GetMethodID
http://stackoverflow.com/questions/7940484/jni-passing-multiple-parameters-in-the-function-signature ...
随机推荐
- Xn数列(codevs 1281)
题目描述 Description 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 输入 ...
- eclipse 中添加工程 Some projects cannot be imported because they already exist in the workspace
第一次从外部文件导入HelloWorld工程到workspace目录中,成功. 删除后,再次从外部导入workspace目录提示 Some projects cannot be imported be ...
- Index on DB2 for z/OS: DB2 for z/OS 的索引
可以创建在任何表上的索引: Unique Index:An index that ensures that the value in a particular column or set of col ...
- webservice 简单入门 (NLY)
1,创建webservice服务器端 搭建网站,创建webservice webservice.cs中的代码 namespace WebApplication1 { /// <summary&g ...
- history 清空历史记录 或 history不记录历史命令
# vi ~/.bash_history 清空里面的记录,并退出当前shell # exit(一定要退出当前shell) # history 1 vi ~/.bash_history 2 histor ...
- VS2010 自动跳过代码现象
今日,发现在Release的调试模式下,VS2010会“莫名其妙”的跳过一些代码不执行. 经实验,初步判断可能的原因:预处理器指令或编译器/连接器优化. 20150703更新: 部分代码: m_pTa ...
- poj 1182:食物链(种类并查集,食物链问题)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44168 Accepted: 12878 Description ...
- Mishka and Interesting sum Codeforces Round #365 (树状数组)
树状数组,与Turing Tree类似. xr[i]表示从1到i的抑或,树状数组维护从1到i每个数只考虑一次的异或,结果为sum(r) ^ sum(l) ^ xr[r] ^ xr[l] 其中xr[r] ...
- Python 遍历文件,字符串操作
写一个简单的脚本,循环遍历单层文件夹,检查源代码中是否有一些特殊的类. import os import codecs dirroot = "......" line_num = ...
- hdu 4028 2011上海赛区网络赛H dp+map离散
一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...