Get Your Silverlight MainPage
Get access to your Silverlight MainPage object
If you ever need to access the MainPage object of your Silverlight application (from elsewhere in that application), simply do this where needed:
MainPage mainPage = App.Current.RootVisual as MainPage;
Bonus Tip: Don't be hesitant to look at the code generated by Visual Studio. I found out wthat the RootVisual
property represents the MainPage
object and is set when the application is started. Once I discovered that, the rest was easy.