如何为 ICommand 设置 EventArg?
在 VM 中,设置 ICommand 如下:
private RelayCommand<EventArgs> _myCommand = null;
public RelayCommand<EventArgs> MyCommand
{
get
{
if (_myCommand == null)
{
_myCommand = new RelayCommand<EventArgs>((e) =>
{
//....
}
);
}
return _myCommand;
}
}
在 xaml 中,绑定到此命令,然后
<Button Content="Test Command" Margin="2,0,2,0" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=InputTextBox, Path=Text}" />
运行应用程序。它说无法将字符串转换为 EventArgs。
如何为 ICommand 绑定设置 EventArgs?
in VM, set ICommand like:
private RelayCommand<EventArgs> _myCommand = null;
public RelayCommand<EventArgs> MyCommand
{
get
{
if (_myCommand == null)
{
_myCommand = new RelayCommand<EventArgs>((e) =>
{
//....
}
);
}
return _myCommand;
}
}
In xaml, binding to this command like
<Button Content="Test Command" Margin="2,0,2,0" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=InputTextBox, Path=Text}" />
then run the app. it say can't convert string to EventArgs.
How to set EventArgs for ICommand binding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉
RelayCommand
我只遇到过RelayCommand
。然而,
RelayCommand
似乎不太有用。我怀疑您至少需要RelayCommand
。I'm not familiar with
RelayCommand<T>
I've only come acrossRelayCommand
.However it would seem that
RelayCommand<EventArgs>
can't possibly be useful. I suspect that you would at least needRelayCommand<string>
.