c# - 在 NavigationService.GoBack 上使用变量

标签 c# windows-phone-8

NavigationService.GoBack();我在 viewmodel 中设置了一个变量,然后我想返回,当我返回时我想使用那个变量,但似乎什么都没有运行,我不想刷新那个页面。

有什么想法吗?

这里我正在设置变量,我想回到我的主页面。

void item_click(object sender, RoutedEventArgs e)
   {

     Button b = e.OriginalSource as Button;

     App.ViewModel.bName = b.Content.ToString();
     App.ViewModel.bID = b.Name;

     this.NavigationService.GoBack();

    }

在我的 MainPage 中,我想运行检查以确定变量是否已更改。

public MainPage()

    {
      /*
i don't want to run this actually, when i'm coming back from my secondarypage.

        InitializeComponent();
        InitializeSettings();

*/

            if (App.ViewModel.bName != null)
            {
                myButton.Content = App.ViewModel.bName;
                myButton.Name = App.ViewModel.bID;
            }
    }

最佳答案

哦,很抱歉这个含糊的问题,但我解决了我的问题。

这在主页中是需要的。

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

        if (App.ViewModel.bName != null)
        {
            myButton.Content = App.ViewModel.bName;
            myButton.Name = App.ViewModel.bID;
        }


        base.OnNavigatedTo(e);

    }

关于c# - 在 NavigationService.GoBack 上使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13948849/

相关文章:

c# - 如何为 ListView 中的子项目添加颜色? C#

c# - 如何在 Html.TextBoxFor 中使用 ShortDate 字符串格式

c# - WP8 中的 SpeechRecognizerUI 导致高崩溃次数?

c# - 在同一文本文件上使用 StreamReader 和 Writer

c# - 我可以使用反射从 EF SqlQuery 获取值名称和值吗

c# - 在 C# 代码的开头和之后更改标签的文本

c# - 如何提高 Windows Phone 8 map 控制性能

c# - 我可以绑定(bind)到实用程序类吗?

c# - 我如何锁定工具包 :LongListMultiSelector in selection mode?

c# - 在 Windows Phone 8.1 中设置系统音量