February 15, 2011

WPF Databinding to User Settings

Used this website as a reference: Binding to User Settings in WPF

In the Xaml add
xmlns:Properties="clr-namespace:XXX.Properties"
to the window/control attributes section where XXX is the application namespace under which the properties are defined

Then to bind a setting
Text="{Binding Source={x:Static Properties:Settings.Default}, Path=SomeSetting, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Note without the 'UpdateSourceTrigger' definition the updating did not work when the update was made programmatically. By default the 'UpdateSourceTrigger' is set to 'FocusChanged' so that only when the control lost it's focus would the change be passed on back to the source.
Why this change worked

No comments: