Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get a page instance from a frame?

Tags:

c#

wpf

xaml

frame

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

like image 906
osh Avatar asked Feb 27 '13 20:02

osh


1 Answers

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;
         }
}
like image 65
Loures Avatar answered Sep 28 '22 10:09

Loures