所以这是我的困境,我想在我的 View 模型上处理 View 事件,麻烦的是,为了添加事件处理程序,我的 View 必须有一个代码隐藏文件,因此必须设置一个类属性。我 99% 确定这是个坏主意,老实说,我什至不确定该怎么做(除了明显的 x:Class=""部分)在MVVM 应用程序?
<ResourceDictionary>
<DataTemplate DataType="{x:Type vm:OutletViewModel}">
<Button Click="IHaveNoBinding">
</DataTemplate>
</ResourceDictionary>
最佳答案
使用commands :
<Button Command="{Binding ACommandOnYourViewModel}"/>
参见 this post我的一个有用的命令实现,你可以在你的 View 模型中使用。
假设您不能使用命令,请使用 attached command behaviors .
关于c# - WPF MVVM 中将 frameworkElement 事件绑定(bind)到 View 模型处理程序的 "proper"方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1312706/