【问题标题】:Wpf - NavigationService.GoBack() and Listbox SelectionChanged EventWpf - NavigationService.GoBack() 和 Listbox SelectionChanged 事件
【发布时间】:2010-10-19 10:00:01
【问题描述】:

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

问题:

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

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

【问题讨论】:

    标签: wpf navigation selectionchanged


    【解决方案1】:

    我使用 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 2012-02-03
      • 2011-05-07
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多