Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top