Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight 3.0 - How to access a MainPage control value from an UserControl

Tags:

c#

silverlight

I need to retrieve some control values from the MainPage to an UserControl. In this UserControl I need to be able to get the Frame.ActualWidth & Frame.ActualHeight values (in this case, the Frame element is in the MainPage and the UserControl is loaded inside a MainPage's Grid via xaml). Does someone have a sample? Thank you

Josimari Martarelli ESL Sistemas Logísticos Silverlight UI Design

[email protected]

like image 748
Learning Xamarin Avatar asked Nov 13 '09 12:11

Learning Xamarin


2 Answers

MainPage m = (MainPage)Application.Current.RootVisual;

like image 163
thomasmartinsen Avatar answered Sep 26 '22 14:09

thomasmartinsen


In instances like this I'll often use have my MainPage class have a public static reference to itself, Instance. I'll set it this "this" in the constructor and then when I need access to the MainPage from down in a user control I'll just call something like:

MainPage.Instance.Foo

like image 30
Casey Margell Avatar answered Sep 23 '22 14:09

Casey Margell