2012-03-11 49 views
2

首先窗体2要更新类文件后没有更新的静态变量重定向

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

类文件,表格1从类文件中检索,这意味着我必须只更新类文件,当它从窗口2到Form1重定向,它会重新加载

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

Form1中(不更新,类似乎仍持有旧的值)

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

在第一次,我开始添加更多的变量并修复我的表单2中的列表后,每个人都工作正常,但没有任何意义。当我调试它,在形式2中,示出了Add按钮= 3的内部形式2

尽管调试回事,我切换到的Class1.cs,值心不是更新(可在其非实时)

无论如何,当它到达form1从class1.cs中检索,它不检索我期待的值

感谢您的帮助! :)

+0

你为什么不只是使用一个查询字符串?你现在有什么不会支持墓碑(你只是存储一个int) - 但使用Querystring将 – 2012-03-11 22:36:35

回答

3

查询字符串的方法

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); 
    } 
1

你可以尝试切换这些语句的顺序,所以重定向之前做了更新:​​

Class1.AddButton = 1; 
Class1.ChiefAnswer = "Done"; 
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative)); 
+0

嗨,我试过了,它并不会帮助 – CodeGuru 2012-03-12 03:33:15