如何在框架页面上方使用Metrowindow的属性
使用Mahapps.metro,并遇到问题。
我想分页页面内容,全部通过地铁窗口内的框架控制。
有两件事我无法弄清楚如何做,这很简单,同时在没有页面的情况下在一个窗口内工作。
首先,我想使用他们的对话框。 以下行直接在窗口中使用时工作:
await this.ShowMessageAsync("This is the title", "User Setting: " + x);
但是,它现在给出以下错误:
实例参数:无法从’GameWindow.MainMenu’转换为’MahApps.Metro.Controls.MetroWindow’
我试图寻找答案,以及尝试诸如此类的事情
await this.Parent.ShowMessageAsync("This is the title", "User Setting: " + x);
但一切都无济于事。
其次,我在我的窗口中配置了一个弹出窗口,我还需要从框架内的页面进行访问。 我不能为我的生活想出这一个…
你必须走在可视化树上才能找到MetroWindow
实例,例如
using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; await this.TryFindParent() .ShowMessageAsync("This is the title", "User Setting: " + x);
TryFindParent<>
是MahApps.Metro.Controls.TreeHelper
定义的扩展方法,而ShowMessageAsync<>
是在MahApps.Metro.Controls.Dialogs.DialogManager
定义的。 如果您不想使用扩展方法,请尝试以下代码:
var window = TreeHelper.TryFindParent(this); await DialogManager.ShowMessageAsync(window, "This is the title", "User Setting: " + x);