none
How to get main page from any part of Windows Phone 8 application? RRS feed

  • Frage

  • I wanted to encapsulate the behavior of a pivot item inside a view class. Apparently, SelectionChanged rotates through every pivot item during startup, so I had to do the following:

    var frame = App.Current.RootVisual as PhoneApplicationFrame;
    
    i
    _pivotSelectedIndex = value;
                        if (_pivotSelectedIndex.Item == ((Pivot)ObjectAsSender).Items[0])
                        {
                            MessageBox.Show("first");
                            container = frame.Content as MainPage;
                            object obj1 = new object();
                        }
                        if (_pivotSelectedIndex.Item == ((Pivot)ObjectAsSender).Items[1])
                        {
                            MessageBox.Show("second");
                            container = frame.Content as MainPage;
                           object obj2 = new object();
                        }
                        if (_pivotSelectedIndex.Item == ((Pivot)ObjectAsSender).Items[2])
                        {
                            MessageBox.Show("third");
                            container = frame.Content as MainPage;
                           object obj3 = new object();
                        }

    could you tell me how to manage it in my ItemModelView class or other class?

    many thanks



    • Bearbeitet bangoura Freitag, 31. Januar 2014 12:55
    Freitag, 31. Januar 2014 12:52

Alle Antworten

  • Hello bangoura,

    when your Mainpage's construcor is called you can store the Elements, that you want to access later from other classes, in static fields inside your Mainpage. They have to be public and static to be accessed by other classes.

    The following code changes an Element's text without being inside your Mainpage.
    (myTextBox is the respective field of the element that has to be altered.)

    MainPage.myTextBox.Text = "testText";

    Regards,
    J. Oldörp     
    Developer-Hotline for MSDN Online Germany

    Disclaimer:
    Please take into consideration, that further inquiries cannot or will be answered with delay.
    For further information please contact us per telephone through the MSDN-Entwickler-Hotline: http://www.msdn-online.de/Hotline
    For this post by the MSDN-Entwickler-Hotline the following terms and conditions apply: Trademarks, Privacy as well as the separate terms of use for die MSDN-Entwickler-Hotline.



    • Bearbeitet J Oldörp Montag, 1. September 2014 13:48
    Montag, 1. September 2014 13:07