【问题标题】:where store event handler method in WPF - MVVM在 WPF 中存储事件处理程序方法的位置 - MVVM
【发布时间】:2010-05-01 18:04:08
【问题描述】:

我应该在哪里存储按钮点击事件的事件方法?通常它存储在 wpf 页面后面的代码中,

<Button Name="myButton" Click="myButton_Click">Click Me</Button>

但在 MVVM 中,它应该存储在其他视图模型类中并绑定到按钮的单击属性??

<Button Name="myButton" Click="{Binding StaticResouces myButton_Click}">Click Me</Button>

【问题讨论】:

    标签: wpf mvvm events


    【解决方案1】:

    使用命令。您的 VM 公开了命令,并且按钮绑定到它:

    <Button Command="{Binding SomeCommand}">Do It!</Button>
    

    请参阅我在 delegate commandsactive aware commands 上的博文,了解如何实现自定义命令的详细信息。

    【讨论】:

    • 感谢您的建议;)我阅读了您的帖子以及网上的更多信息,希望这能解决我的问题:)
    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2010-10-16
    • 2010-12-05
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 2016-10-31
    相关资源
    最近更新 更多