Wpf - NavigationService.GoBack()和Listbox SelectionChanged事件

时间:2010-10-19 10:00:01

标签: wpf navigation selectionchanged

在ADDPage.xaml页面中,我有一个带有代码NavigationService.GoBack()的后退按钮,可以返回上一页。

问题:

在另一个页面的Listbox SelectionChanged事件(SubPage.xaml)中,我正在使用NavigationService.Navigate(新的ADDPage(搜索));

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

1 个答案:

答案 0 :(得分:0)

我使用Delegate解决了我的问题。

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