MVVM : Share data between ViewModels

前端 未结 5 866
一个人的身影
一个人的身影 2021-01-02 00:25

How do I share data between multiple ViewModels ?

For example there is a class named Project in application .

    public class Project : ModelB         


        
5条回答
  •  情书的邮戳
    2021-01-02 00:51

    Singleton will definitely help. To implement, if I had a class named User:

        private static User mInstance;
    
        private User () //constructor
        {
        }
    
        public static User Instance
        {
            get
            {
                if (mInstance == null)
                    mInstance = new User();
                return mInstance;
            }
        }
    

提交回复
热议问题