Calling a method in MainPage.xaml.cs from App.xaml.cs in WP8 App

In a Windows Phone 8 App, we sometimes need to call a method in MainPage.xaml.cs from a different class (App.xaml.cs for instance). And we might not be able to make it a static method.

There is a simple way to achieve this. Just create a static instance of the MainPage class in the class itself. Check the code below.

Calling a method in MainPage.xaml.cs from App.xaml.cs in WP8 App

After this, you can simply call a method using…

MainPage.instance.DoSomeWorkInMainPage();

Share This!

3 thoughts on “Calling a method in MainPage.xaml.cs from App.xaml.cs in WP8 App

  1. The XAML remains the same. The Click Event would look like this Private Sub RadioButton_Click_1(sender As Object, e As RoutedEventArgs) Dim radBtn = TryCast(sender, RadioButton) If radBtn IsNot Nothing Then Dim index As Integer = Convert.ToInt32(radBtn.Tag) _flipVw.SelectedIndex = index End If End SubThat’s it.. Thanks for the comemnt.

Leave a Reply

Your email address will not be published. Required fields are marked *