Search code examples
c#silverlightwindows-phone-7

Static variable not updating after redirect


First Form2 wants to update Class file

private void button1_Click(object sender, RoutedEventArgs e)
        {
           NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
           Class1.AddButton = 1;
           Class1.ChiefAnswer = "Done";
        }

Class File, form 1 retrieve from class file, meaning i have to just update the class file and when it redirect from form2 to form1 , it will reload

private static int AddBtn = 0;
public static int AddButton
        {
            get { return AddBtn; }
            set { AddBtn = value; }
        }

Form1(Not updated, the class seems to still hold a older value)

 if (Class1.AddButton == 3)
 {
     MakeButton();
 }

At fist everyone was working fine after i started to add more variables and fixing the list in my form 2, it didnt work which didnt make sense. When i debugged it , in form 2 , it shows that the AddButton = 3 inside form 2

While debugging is going on , i switch to class1.cs , the value isnt updated(may its not real time)

Anyway , by the time it reaches form1 which retrieves from class1.cs, its not retrieving the value i'm expecting

Thanks for you help! :)


Solution

  • querystring method

    NavigationService.Navigate(new Uri("/PanoramaPage1.xaml?selected=item2", UriKind.Relative));
    
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string selected = String.Empty;
    
            //check to see if the selected parameter was passed.
            if (NavigationContext.QueryString.ContainsKey("selected"))
            {
                //get the selected parameter off the query string from MainPage.
                selected = NavigationContext.QueryString["selected"];
            }
    
            //did the querystring indicate we should go to item2 instead of item1?
            if (selected == "item2")
            {
                //item2 is the second item, but 0 indexed. 
                myPanorama.DefaultItem = myPanorama.Items[1];
            }
            base.OnNavigatedTo(e);
        }