2010-10-19 107 views
1

在ADDPage.xaml页面中,我有一个返回按钮,代码NavigationService.GoBack()返回上一页。Wpf - NavigationService.GoBack()和Listbox SelectionChanged事件

问题:

在另一页的列表框SelectionChanged事件(SubPage.xaml)我使用NavigationService.Navigate(新ADDPage(搜索));

当页面执行ADDPage.xaml页面的NavigationService.GoBack()时,控件将移动到SubPage.xaml的Listbox SelectionChanged事件,并再次加载相同的页面。有没有更好的解决方案?

回答

0

我用委托来解决我的问题。

SubPage.xaml.cs

public delegate void RefreshHandle(string message); 

public partial class SubPage : PhoneApplicationPage 
{ 
    public static RefreshHandle RefreshCallback; 

    void Button_Click(object sender, EventArgs e) 
    { 
     string msg = "Test"; 
     RefreshCallback(msg); 
     NavigationService.GoBack(); 
    } 
} 

MainPage.xaml.cs中

public partial class MainPage : PhoneApplicationPage 
{ 
    public MainPage() 
    { 
     SubPage.RefreshCallback += new RefreshHandle(RefreshFn); 
    } 
    void RefreshFn(string message) 
    { 
     MessageBox.Show(message); 
    } 
} 
相关问题