How to use properties from Metrowindow above framed page

扶醉桌前 提交于 2019-12-08 10:50:52

问题


Using Mahapps.metro, and stumbling into a problem.

I want to page paged content, all controlled via a frame within metro window.

There are two things I cannot figure out how to do, which was easy enough whilst working all within one window without the pages.

First off, I want to use their dialogs. The following line worked previousely whilst used directly within the window:

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

However, it now gives the following error:

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

I have tried searching for an answer, as well as trying things such as

await this.Parent.ShowMessageAsync("This is the title", "User Setting: " + x);

but all to no avail.

Secondly, I have a flyout configured in my window, which I need to access from a page within the frame also. I cannot for the life of me figure this one out either...


回答1:


You have to walk up the visual tree to find the MetroWindow instance, e.g.

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

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

TryFindParent<> is an extension method defined in MahApps.Metro.Controls.TreeHelper, and ShowMessageAsync<> is defined in MahApps.Metro.Controls.Dialogs.DialogManager. If you don't want to use extension methods, try this code:

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


来源:https://stackoverflow.com/questions/28793822/how-to-use-properties-from-metrowindow-above-framed-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!