如何在框架页面上方使用 Metrowindow 的属性

How to use properties from Metrowindow above framed page

使用 Mahapps.metro,遇到问题。

我想分页内容,全部通过 metro window 中的框架控制。

有两件事我不知道该怎么做,但在没有页面的情况下在一个 window 中工作时很容易。

首先,我想使用他们的对话框。以下行在 window:

中直接使用时以前有效
await this.ShowMessageAsync("This is the title", "User Setting: " + x);

但是,它现在给出以下错误:

Instance argument: cannot convert from 'GameWindow.MainMenu' to 'MahApps.Metro.Controls.MetroWindow'

我曾尝试寻找答案,也尝试过诸如

之类的尝试
await this.Parent.ShowMessageAsync("This is the title", "User Setting: " + x);

但都无济于事。

其次,我在 window 中配置了弹出窗口,我还需要从框架内的页面访问它。我这辈子也想不通...

您必须沿着视觉树向上走才能找到 MetroWindow 实例,例如

using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

await this.TryFindParent<MetroWindow>()
    .ShowMessageAsync("This is the title", "User Setting: " + x);

TryFindParent<>MahApps.Metro.Controls.TreeHelper中定义的扩展方法,ShowMessageAsync<>MahApps.Metro.Controls.Dialogs.DialogManager中定义的扩展方法。如果你不想使用扩展方法,试试这个代码:

var window = TreeHelper.TryFindParent<MetroWindow>(this);
await DialogManager.ShowMessageAsync(window, "This is the title", "User Setting: " + x);