How can I save global application variables in WPF?

前端 未结 4 1055
既然无缘
既然无缘 2020-12-31 13:52

In WPF, where can I save a value when in one UserControl, then later in another UserControl access that value again, something like session

4条回答
  •  旧时难觅i
    2020-12-31 14:08

    Something like this should work.

    public static class ApplicationState 
    { 
        private static Dictionary _values =
                   new Dictionary();
    
        public static void SetValue(string key, object value) 
        {
            _values.Add(key, value);
        }
    
        public static T GetValue(string key) 
        {
            return (T)_values[key];
        }
    }
    

提交回复
热议问题