@CSharper's answer did not work for my WPF application encoded in VB.NET (not C #, unlike, apparently, 99.999% of other WPF applications), since I got a constant compiler error complaining that Settings
could not be found in MyApp.Properties
namespace that will not disappear even after recovery.
Which worked for me after searching the Internet multiple times, instead using the local
XAML namespace, created by default in the main XAML application window:
<Window <!-- Snip --> xmlns:local="clr-namespace:MyApp" <!-- Snip --> ></Window>
... and bind to my settings through it, using something like the following (where MyBooleanSetting
is the parameter that I defined in my project properties like Boolean
and the user area with the default access modifier):
<CheckBox IsChecked="{Binding Source={x:Static local:MySettings.Default}, Path=MyBooleanSetting, Mode=TwoWay}" Content="This is a bound CheckBox."/>
To make sure that the settings are really saved, be sure to call
MySettings.Default.Save()
... somewhere in your code (for example, in the Me.Closing
event for your MainWindow.xaml.vb
file).
(Remember this post in Visual Studio for inspiration; see Muhammad Siddiqui's answer.)
Christopher Kyle Horton Feb 24 '16 at 15:51 2016-02-24 15:51
source share