c# - System.NullReferenceException when initialization -


this question has answer here:

i have window named 'mainwindow' 2 frames named 'mainframe','sidepanel' , in 'mainwindow', when click 'btn1' 'sidepanel', 'mainframe' navigated 'frame1' page. in 'frame1', have border control 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 page;     var border = page.content border; } 

i'm having "system.nullreferenceexception" when initializing border page.content=null. if click 'btn1' 2nd time, initialized 'system.windows.controls.border'. want result when click 'btn1' 1st time.

please, me solution.

as @kookiz suggested, 1 gave me solution:

frame1.xaml.cs:

private void page_loaded(object sender, routedeventargs e) {     var page = ((mainwindow)app.current.mainwindow).mainframe.content page;     var border = page.content border; } 

frame1.xaml:

<page loaded="page_loaded">     <border></border> </page> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -