Silverlight 3.0 - How to Access the MainPage Control from UserControl

I need to get some control values ​​from MainPage in UserControl. In this UserControl, I need to get the values ​​Frame.ActualWidth and Frame.ActualHeight (in this case, the Frame element is in MainPage, and UserControl is loaded inside the MainPage grid via xaml). Does anyone have a sample? thank you

Yosimari Martarelli ESL Sistemas Logísticos UI Design Silverlight

jmartarelli@logfacil.com.br

+5
source share
4 answers

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

+7
source

, , , MainPage , . "this" , , MainPage - , - :

MainPage.Instance.Foo

+1

App, , . MainPage. FrameworkElement.

    public static FrameworkElement GetParentByName(FrameworkElement currentPage, 
string ParentName)
    {

        FrameworkElement fe = (FrameworkElement)currentPage.Parent;

        // Walk your way up the chain of Parents until we get a match
        while(fe.GetType().Name != ParentName)
            fe = (FrameworkElement)fe.Parent;

        return fe;

    }

, , - :

MainPage m = (MainPage) App.GetParentByName(, "MainPage" );

+1

, .

ie Login lp = (Login)Application.Current.RootVisual;
You can use the option created on the login page.

0
source

All Articles