gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:37:00 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com