【问题标题】:Two commands to one button两个命令到一个按钮
【发布时间】:2015-05-26 04:07:18
【问题描述】:

我想将两个操作绑定到 ModernUI 链接:单击时,它应该 a) 触发 RelayCommand 和 b) 导航。我已经用谷歌搜索并阅读但找不到解决方案。到目前为止,我只进行了绑定或导航,但不能同时进行两者..

例如在示例 ModernUI 应用程序中,导航发生如下:

                <Button Content="introduction" Margin="0,0,4,0"
                        Command="mui:LinkCommands.NavigateLink"
                        CommandParameter="/Pages/Introduction.xaml"/>

但是Command 属性已经被使用了,那么我怎么能将我的第二个Command 附加到它呢?

                <Button Content="introduction"
                        Command="{Binding MyCommand}">

我也尝试过使用ListBox,我可以使用SelectedItem 属性,但是这个没有Command 属性。

非常感谢您的提示!

【问题讨论】:

  • 为什么不在视图模型的 MyCommand 中调用 LinkCommand?
  • 我也试过了,但是当导航标签栏没有反映当前页面时卡住了,还认为这违反了MVVM?
  • 这能回答你的问题吗? Binding two commands to one button?

标签: c# wpf command modern-ui


【解决方案1】:

CodeProject 站点显示了Commands 列表的实现,该列表将自己呈现为一个命令。这样一来,呼叫一个就会呼叫其他人。

事实上,这个类只是实现了ICommand一个ObservableCollection,其中Commands 在被调用时会被执行。

这似乎是您问题的正确解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多