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);
精彩评论