65.9K
CodeProject is changing. Read more.
Home

Get Your Silverlight MainPage

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.95/5 (9 votes)

May 9, 2011

CPOL
viewsIcon

22994

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.