Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Kris, I'm not sure this is the best way to bind ApplicationSettings, but this is how I did it in <a href="http://code.google.com/p/wittytwitter/" rel="nofollow noreferrer">Witty</a>.</p> <p>1) Create a dependency property for the setting that you want to bind in the window/page/usercontrol/container. This is case I have an user setting to play sounds.</p> <pre><code> public bool PlaySounds { get { return (bool)GetValue(PlaySoundsProperty); } set { SetValue(PlaySoundsProperty, value); } } public static readonly DependencyProperty PlaySoundsProperty = DependencyProperty.Register("PlaySounds", typeof(bool), typeof(Options), new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnPlaySoundsChanged))); private static void OnPlaySoundsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { Properties.Settings.Default.PlaySounds = (bool)args.NewValue; Properties.Settings.Default.Save(); } </code></pre> <p>2) In the constructor, initialize the property value to match the application settings</p> <pre><code> PlaySounds = Properties.Settings.Default.PlaySounds; </code></pre> <p>3) Bind the property in XAML</p> <pre><code> &lt;CheckBox Content="Play Sounds on new Tweets" x:Name="PlaySoundsCheckBox" IsChecked="{Binding Path=PlaySounds, ElementName=Window, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /&gt; </code></pre> <p>You can download the full <a href="http://code.google.com/p/wittytwitter/" rel="nofollow noreferrer">Witty source</a> to see it in action or browse just the <a href="http://code.google.com/p/wittytwitter/source/browse/trunk/Witty/Witty/Options.xaml.cs" rel="nofollow noreferrer">code for options window</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload