locked
How to refer to MainPage? RRS feed

  • Question

  • Hi, been using VB 2010, and now using 2013 to write a phone app, getting the hang of it.

    How do I refer to the MainPage? Previously, my main page was a FORM object, so I could call a function like Form1.Beep () or refer to a control with Form1.ListBox1. ect

    How do I do this now, MainPage is the class, so calling MainPage.Beep() does not work, but I just can't find the object name, or how to set it.

    Thanks in advance.

    Thursday, February 12, 2015 9:48 AM

Answers

  •        public MainPage()
            {
                InitializeComponent();
                Instance = this;
    
             }
    
     public static MainPage Instance { get; private set; }
    
    // In another page:
    
    MainPage.Instance.SomeMethod();


    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

    • Marked as answer by Chrispys Thursday, February 12, 2015 11:01 AM
    Thursday, February 12, 2015 10:40 AM
  • Thank you, I had seen that before, but as I have not done any C for so long I did not understand it then but now I get the idea.

    So in basic it will be...

    In another page:

     Public TheMainPage As MainPage

    and in main page:

     Sub New()
            InitializeComponent()
            TheMainPage = Me

    End Sub

    Tested that, simple when you know how :)

    • Marked as answer by Chrispys Thursday, February 12, 2015 11:01 AM
    Thursday, February 12, 2015 11:00 AM

All replies

  •        public MainPage()
            {
                InitializeComponent();
                Instance = this;
    
             }
    
     public static MainPage Instance { get; private set; }
    
    // In another page:
    
    MainPage.Instance.SomeMethod();


    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

    • Marked as answer by Chrispys Thursday, February 12, 2015 11:01 AM
    Thursday, February 12, 2015 10:40 AM
  • Thank you, I had seen that before, but as I have not done any C for so long I did not understand it then but now I get the idea.

    So in basic it will be...

    In another page:

     Public TheMainPage As MainPage

    and in main page:

     Sub New()
            InitializeComponent()
            TheMainPage = Me

    End Sub

    Tested that, simple when you know how :)

    • Marked as answer by Chrispys Thursday, February 12, 2015 11:01 AM
    Thursday, February 12, 2015 11:00 AM