每次用户更改设置页面内的选项时,是否有任何方法可以重新加载主页?

发布于 2025-02-09 18:04:56 字数 1048 浏览 1 评论 0原文

我有一个设置页面,可以在其中设置全局变量(0米,1-帝国),

我有主页需要重新加载并每次更改此变量时(从Picker Insideins设置页面)更改文本值

(我尝试过我尝试使用( ) 功能。但是文字保持不变。 (启动应用程序时只能使用一次)

代码(关于页面):

protected override void OnAppearing()
    {

        base.OnAppearing();

        int system = ((App)App.Current).system_global; //global varible changed from settings page
        test.Text = system.ToString(); //used for debug

        //Metric
        if (system == 0)
        {
            devide = 100;

            Label_distance.Text = "Distance travelled (km):";
        }

        //Imperial
        else if (system == 1)
        {
            devide = 1;

            Label_distance.Text = "Distance travelled (miles):";
    }

代码(设置页面):

private void Picker_SelectedIndexChanged(object sender, EventArgs e)
    {
        system = Picker_Settings.SelectedIndex; //change global variable to 0 or 1
        test.Text = "Update:" + system.ToString(); //debug
    }

每次用户更改picker内部的选项时,是否有任何方法可以重新加载有关页面?

I have a settings page where I can set the global variable (0-Metric , 1-Imperial)

I have main page that I need to reload and change text values everytime this variable is changed (from picker inside Settings page)

I tried OnAppearing() function. But the text stays the same. (Code works only once when starting app)

Code (AboutPage):

protected override void OnAppearing()
    {

        base.OnAppearing();

        int system = ((App)App.Current).system_global; //global varible changed from settings page
        test.Text = system.ToString(); //used for debug

        //Metric
        if (system == 0)
        {
            devide = 100;

            Label_distance.Text = "Distance travelled (km):";
        }

        //Imperial
        else if (system == 1)
        {
            devide = 1;

            Label_distance.Text = "Distance travelled (miles):";
    }

Code (Settings page):

private void Picker_SelectedIndexChanged(object sender, EventArgs e)
    {
        system = Picker_Settings.SelectedIndex; //change global variable to 0 or 1
        test.Text = "Update:" + system.ToString(); //debug
    }

Is there any way to reload AboutPage every time when user changes an option inside the picker?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧故 2025-02-16 18:04:56

可能发生的事情是,您通过弹出堆栈将导航回另一页。这意味着最新页面刚刚被删除,但前面的页面并未被告知重新加载。它只是再次显示。

因此,我建议您重新散布回到上一页,以重新调整所有内容。另一个选择是使用消息传递中心,并在更改值时使用。这样,您也可以从设置页面触发数据刷新,也可以

https://learn.microsoft.com/en-us/xamarin/xamarin/xamarin-forms/app-fundamentals/messaging-center

What is probably happening is that you're navigating back to the other page by Popping the stack. This means that the most recent page is just getting removed but the previous page isn't being told to reload. It's just showing again.

So I'd recommend re-navigating back to the previous page to re-initialise everything. The other option is to make use of a Messaging center and use that when you change your values. That way you can trigger the data refresh from the Settings page as well

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文