2010-10-19 72 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); 
    } 
} 
相關問題