开发者

Get the window from a page

How to get a window from a page , so I've got a page frame in my window :

<Frame NavigationUIVisibility="Hidden" Name="frmContent" Source="Page/Page1.xaml" OverridesDefaultStyle="False" Margin="0,0,0,0"  />

And trying to access my window from this page this way :

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    if ((Window1)this.Parent == null)
        System.Windows.Forms.MessageBox.Show("111");
    else
    wb1.ObjectForScripting = new MyScriptObject((Window1)this.Parent);

But the Parent returns null , so I see "111" message,

Where is my mistake and how to get window开发者_如何学Go object correct ?


The parent of the page will be the Frame, not the Window.

The easiest way is to use the Window.GetWindow static method:

var wnd = Window.GetWindow(this);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜