Passing a complex object to a page while navigating in a WP7 Silverlight application

前端 未结 5 1425
礼貌的吻别
礼貌的吻别 2020-11-30 06:05

I have been using the NavigationService\'s Navigate method to navigate to other pages in my WP7 Silverlight app:

NavigationService.         


        
5条回答
  •  离开以前
    2020-11-30 06:45

    Debatable solution, if anything, make it temporary.

    Create this under the namespace of your application for whichever page necessary.

    public static class VarsForPages {
    
        // Be sure to include public static.
        public static SomeClass SomeClassObject;
        public static List SomeList = new List();
        public static string SomeData = "SomeValue";
    
    }
    
    // The syntax for referencing the data
       VarsForPages.SomeClassObject; 
       VarsForPages.SomeList; 
       VarsForPages.SomeData;
    

    Now you can reference SomeClassObject, SomeList, SomeData anywhere in the application.

    Note: Like any global data, be weary of the many accesses & modifications which may be done to the global data. I say this, because I once had a list increase in size, but one of my pages in the application relied on the size of the list to be of some value, and this caused a bug. Don't forget, the data is global.

提交回复
热议问题