问题描述
<window> <Frame Name="myframe" NavigationUIVisibility="Hidden" Source="mypage.xaml"/> </window>
我正在尝试从包含框架(按顺序包含页面)中的窗口中获取页面实例,而我不知道如何获得.
public partial class mywindow : Window { public mywindow() { BusinessLogic.Initialize(); InitializeComponent(); var a = myframe.Content; } }
我如何得到它?
谢谢
推荐答案
您的代码是正确的,但缺乏内容的返回.
public partial class mywindow : Window { public mywindow() { BusinessLogic.Initialize(); InitializeComponent(); var a = (MyPage)myframe.Content; } }
其他推荐答案
我想这个解决方案应该解决问题吗?
by Type /p>
FindVisualChildren<Frame>(this).FirstOrDefault()
问题描述
I have a frame that i initialized in xaml like this:
<window> <Frame Name="myframe" NavigationUIVisibility="Hidden" Source="mypage.xaml"/> </window>
I'm trying to get the page instance from the window that contains the frame (which in order contains the page) in c# code and i don't know how to get it.
public partial class mywindow : Window { public mywindow() { BusinessLogic.Initialize(); InitializeComponent(); var a = myframe.Content; } }
how do i get it?
thank you
推荐答案
Your code is correct, but lack cast the return of Content.
public partial class mywindow : Window { public mywindow() { BusinessLogic.Initialize(); InitializeComponent(); var a = (MyPage)myframe.Content; } }
其他推荐答案
I imagine this solution should do the trick?
Find all controls in WPF Window by type
FindVisualChildren<Frame>(this).FirstOrDefault()