在WinForms中,我们可以为按钮指定DialogResult。在WPF中,我们可以在XAML中声明只有取消按钮:WPF DialogResult声明?
<Button Content="Cancel" IsCancel="True" />
对于其他人,我们需要赶上ButtonClick,写这样的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
我使用MVVM,所以我只为XAML代码视窗。但对于模态窗口,我需要编写这样的代码,我不喜欢这样。有没有一种更优雅的方式在WPF中做这样的事情?
重复:http://stackoverflow.com/questions/ 501886/wpf-mvvm-newbie-how-view-model-close-the-form – 2010-07-24 21:52:31
我曾经感觉这种关于在MVVM中使用代码的方式,但说实话,我认为在*后面的代码中设置单个标志是*最优雅的解决方案。为什么要对抗它。写一个复杂的附加行为是没有意义的。 – craftworkgames 2015-08-31 05:40:46