6

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

osh
  • 81
  • 1
  • 5
  • 1
    Welcome to SO! Just so you know, we need to see [what you have tried first](http://mattgemmell.com/2008/12/08/what-have-you-tried/); before we can truly help you. So, post up your code thus far! – Brian Feb 27 '13 at 21:02
  • thank you very much! i tried : var a = myframe.Content; – osh Feb 27 '13 at 21:04
  • Sorry, I should have been more specific. Please post your code in your original post :) – Brian Feb 27 '13 at 21:06

2 Answers2

7

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;
         }
}
Loures
  • 433
  • 3
  • 10
1

I imagine this solution should do the trick?

Find all controls in WPF Window by type

 FindVisualChildren<Frame>(this).FirstOrDefault()
Community
  • 1
  • 1
Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122