【问题标题】:WPF MVVM mahapps can't close Custom DialogWPF MVVM mahapps 无法关闭自定义对话框
【发布时间】:2015-12-08 02:54:10
【问题描述】:

好吧,我一直在关注 mahapps Metro 演示应用程序,我通过 MVVM 看到了自定义对话框,是的,它运行良好,但是我再次使用 UserControl 作为正在显示的自定义对话框的内容。

private async void OpenUserAccountDialog()
        {
            CustomDialog = new CustomDialog() { Content = new CreateUserDialog() };
            await DialogCoordinator.ShowMetroDialogAsync(this, CustomDialog);
        }

上面的代码完美运行。 访问 MainViewModel 没问题,我可以这样做:

public ActionCommand CloseDialogCommand
        {
            get
            {
                return new ActionCommand(p => CloseDialog());
            }
        }

然后从我的 XAML 中调用它:

Command="{Binding DataContext.CloseDialogCommand, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type views:MainWindow}}}"

现在的问题是,由于某种未知原因,关闭对话框的命令不会触发(即 MainViewModel)。访问 MainViewModel 是从 UserControl 到 UserControl,但现在它已从对话框中打开,我似乎无法使用上述 XAML 中的相同代码在关闭对话框的 MainViewModel 中触发 ActionCommand。

我已经被困在这里好几天了。我希望有人可以在这里帮助我。

【问题讨论】:

    标签: wpf mvvm dialog


    【解决方案1】:

    似乎我只需要为所有这些创建一个 DialogService 类。我让这一切在 MVVM 中完美运行。

    【讨论】:

      猜你喜欢
      • 2011-09-18
      • 2011-09-09
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多