문제

This has been my issue for long time,i have a method inside the main page to open application, i need to invoke it when the user control is clicked. so when creating a usercontrol i need to pass this method and call it inside the usercontrol click event.

Right now am doing like this,

   private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MainPage m = new MainPage();
            m.openApplication("STOCK");
        }

But its throwing a null reference exception.Help me on this.

도움이 되었습니까?

해결책

Rather than creating an instance of your mainpage, you can pass the mainpage as an argument to the usercontrol and do it like below,

    Usercontrol(Mainpage m);

    private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            m.openApplication("STOCK");
        }

Creating an instance will make null references if values are not assigned.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top