Best practices for storing UI settings?

前端 未结 7 1705
忘掉有多难
忘掉有多难 2020-12-13 21:49

we\'re currently planning a larger WPF LoB application and i wonder what others think being the best practice for storing lots of UI settings e.g.

  • Expander Sta
7条回答
  •  攒了一身酷
    2020-12-13 22:43

    The quicker way to store UI settings is using the Properties.Settings.Default system. What can be nice with it is to use WPF binding to the value. Example here. Settings are automatically updated and loaded.

    
    
    ...
    protected override void OnClosing(System.ComponentModel.CancelEventArgs e) 
    { 
        Settings.Default.Save(); 
        base.OnClosing(e); 
    }
    

    The problem with that is that it quickly becomes a mess if your application is large.

    Another solution (proposed by someone here) is to use the ApplicationData path to store your own preferences into XML. There you can build your own setting class and use the XML serializer to persist it. This approach enables you to do migration from versions to versions. While being more powerful, this method requires a bit more code.

提交回复
热议问题