mvvm模式下 command如何传递多个参数

钱耀祖 2012-10-25 01:59:33
如题
...全文
992 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
smallfile 2012-10-26
  • 打赏
  • 举报
回复
解决方案一:
将多参数转为一个参数,即定义一个包含多参数的类

解决方案二:
若多个参数都隶属datacontext时,你懂的。。。
jwterlt 2012-10-25
  • 打赏
  • 举报
回复
不知道你MVVM用的是什么方式。
可参考一下

添加引用 System.Windows.Interactivity

添加命名空间 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

Xmal中


<Button x:Name="btnTest" Content="点击试试" Width="75" Height="30">

<i:Interaction.Triggers>

<i:EventTrigger EventName="MouseLeftButtonUp" >

<i:InvokeCommandAction Command="{Binding ClickCommand}" CommandParameter="农夫it站nongfuit.com"/>

</i:EventTrigger>

</i:Interaction.Triggers>

</Button>

ViewModel中


public ICommand ClickCommand

{

get

{

return new DelegateCommand<string>(x =>

{

MessageBox.Show("View中触发了点击事件,传递参数:" + x);

});

}

}



说明:
一: EventName="MouseLeftButtonUp" 表示鼠标左键点击弹起时触发事件

二:如果要传Button中的属性到ViewModel,如传递Button的Content到ViewModel,把CommandParameter改为 CommandParameter="{Binding Content, ElementName=btnTest}" 即可;如传Button的Width到ViewModel,把CommandParameter改为 CommandParameter="{Binding Width, ElementName=btnTest}" 即可

wwwljh 2012-10-25
  • 打赏
  • 举报
回复
???
你传一个参数或不传参数的Command是什么写的?

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧