I have a window named 'mainWindow' with two frames named 'mainFrame','sidepanel' and in 'mainWindow', when I click 'btn1' from 'sidepanel', 'mainFrame' is navigated to 'frame1' which is a Page. In 'frame1', I have a Border control as only child.
mainWindow.xaml.cs:
((mainWindow)App.Current.MainWindow).mainFrame.Navigate(new frame1());
frame1.xaml:
<Border>
</Border>
frame1.xaml.cs:
public frame1()
{
InitializeComponent();
var page = ((mainWindow)App.Current.MainWindow).mainFrame.Content as Page;
var border = page.Content as Border;
}
I'm having "System.NullReferenceException" when initializing border as page.Content=null. But if I click 'btn1' for the 2nd time, it is initialized with 'System.Windows.Controls.Border'. But I want this result when I click 'btn1' for the 1st time.
Please, help me with a good solution.