【发布时间】: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。
我已经被困在这里好几天了。我希望有人可以在这里帮助我。
【问题讨论】: