How to store app settings?
I am doing a wpf application and I use application settings in app.config file:
var datapath = Properties.Settings.Default.DataSource;
...
How to make application to load the app.config file, if it present from the same location where exe file run from., so user can change app.config and run it with new settings. By def开发者_开发问答ault app.config ignored and application uses always default settings
You can save and restore any settings using Binding in TwoWay mode. TwoWay needed for auto storing changes of property. For example binding height of the window:
Height="{Binding Source={x:Static self:Properties.Settings.Default},
Path=ApplicationHeight, Mode=TwoWay}"
To make binding works you need to create setting record in project properties (with name ApplicationHeight in example). To save setting on app closing use:
Properties.Settings.Default.Save();
in Window.Closed or Application.Exit events.
精彩评论