How can I save global application variables in WPF?

前端 未结 4 1060
既然无缘
既然无缘 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条回答
  •  渐次进展
    2020-12-31 14:33

    The Application class already has this functionality built in.

    // Set an application-scope resource
    Application.Current.Resources["ApplicationScopeResource"] = Brushes.White;
    ...
    // Get an application-scope resource
    Brush whiteBrush = (Brush)Application.Current.Resources["ApplicationScopeResource"];
    

提交回复
热议问题