WPF MVVM mahapps 无法关闭自定义对话框
WPF MVVM mahapps can't close Custom Dialog
好吧,我一直在关注 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,但现在它是从 Dialog 打开的,我似乎无法使用上面的相同代码触发 MainViewModel 中关闭 Dialog 的 ActionCommand XAML.
我被困在这里好几天了。我希望有人能帮助我。
看来我只需要为所有这些创建一个 DialogService Class。我在 MVVM 中完美地完成了所有工作。
好吧,我一直在关注 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,但现在它是从 Dialog 打开的,我似乎无法使用上面的相同代码触发 MainViewModel 中关闭 Dialog 的 ActionCommand XAML.
我被困在这里好几天了。我希望有人能帮助我。
看来我只需要为所有这些创建一个 DialogService Class。我在 MVVM 中完美地完成了所有工作。