[UWP]重置了绑定属性 [英] [UWP]Binded properties reset

查看:60
本文介绍了[UWP]重置了绑定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用  INotifyPropertyChanged创建了一个类(myProperties) 我在其中有一个属性,用于更改bool变量。 然后我用它来绑定一个splitview.isopen这一切都很好,当我启动应用程序时值为false所以没有拆分
视图。 当我点击一个按钮时,我将其更改为true,并且splitview应该是可见的。 现在,如果我转到其他页面,则返回值默认值返回false。 我希望它记住最后一个值,无论我是否切换页面

I created a class (myProperties) with the INotifyPropertyChanged  and I have a property in it that changes a bool variable.  I then use it to bind a splitview.isopen this all works great when I fire up the app the value is false so no split view.  When I hit a button I change this to true and the splitview is visible as it should be.  Now if I go to a different page then come back the value defaults back to false.  I want it to remember the last value no matter if I switch pages or not.

我相信它是因为在我的主页上我做了以下 

I believe its because On My main page I do the following 

MyProperties UpdateChanges = new MyProperties ();

我试过让事情变得静止但是这也不起作用。 任何帮助都会非常感激。

Iv'e tried making things static but that doesn't work either.  Any help with this would greatly appreciated.

Paul

推荐答案

所以基于你的话,你试图保存一个值在你的申请中。 一种可能的方法是,您可以尝试在应用类中创建一个变量。 更改类中的属性后,将其保存在App类中。每次导航时创建
类时,从APP类中获取值并在 构造函数中设置为target属性。我将提供一个非常简单的代码片段,您可以参考。

So based on your word, you are trying to save a value in you application.  A possible ways is that you could try to create a variable in the app class.  Once the property in your class is changed, save it in App class. When you create your class every time you navigate back, get the value from APP class and set to the target property in the Constructor. I will give a very simple code snippet that you could refer.

像这样:

 sealed partial class App : Application
    {
        public bool isOpen { get; set; }
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
            //for example
            isOpen = false;
        }

以及如何在操作中访问它

And how to access it in manipage

 public sealed partial class MainPage : Page
    {
        public bool targetProperty { get; set; }
        public MainPage()
        {
            this.InitializeComponent();

            App myapp = (App)Application.Current;
            targetProperty= myapp.isOpen;
            
        }

致以最诚挚的问候,

Roy


这篇关于[UWP]重置了绑定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆