Thursday, April 21, 2011

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

Hello, 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

jmartarelli@logfacil.com.br

From stackoverflow
  • MainPage m = (MainPage)Application.Current.RootVisual;

  • 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

0 comments:

Post a Comment