So i am in some window2 from this window I tried get frame defined in MainWindow.xaml
by creating a object of Mainwindow and tried to Navigate to a page but program giving ” null reference exception unhandeled by user code”
I used:
public Window2()
{
}
myfunction()
{
MainWindow rootwindow = new MainWindow();
rootwindow.myframe.Navigate( new Page1());
}
This is not how you get the frame from another window, you are just creating a new window and try to access something which is not loaded yet as the window you just created has not even been shown yet.
You need a reference to your window, which you could get from
Application.Current.MainWindowif you set that accordingly beforehand (e.g. in theAppclass). Or you could pass a reference to the main window in the constructor of your second window.