[EDIT: I figured out that this only applies for ComboBox controls, so this isn't the problem I thought it was. I've updated the description with the new information]
Hi,
I'm curious about the recommended architecture for saving application settings that are slightly more complex than what would be easy with the designer. I've done a fair amount of searching on the web, but I haven't come up with a clean answer yet.
I've overridden ApplicationSettingsBase using the property logic I'd like, and the elements (once set) are saved and stored correctly. However, I'm running into some difficulty trying to get it to work seamlessly with the application view. I have my base class bound to a static resource in the XAML resources:
<Grid.Resources><src:ApplicationsSettings x:Key="Settings"/></Grid.Resources>
That's nice. When exiting, I'm calling ApplicationSettings.Default.Save() and everything is great. EXCEPT for the properties of ComboBoxes. (Sorry for the confusion: that's the primary data that will be saved, so at first I didn't notice that everything else was being saved just fine.)
Here's my combobox:
<ComboBox MinWidth="75" SelectedItem="{Binding Source={StaticResource Settings}, Path=Default.DefaultLocale, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding ElementName=Window_Main, Path=LocaleList}" Name="ctlLocaleComboBox" SelectionChanged="ctlLocaleComboBox_SelectionChanged" Margin="2"></ComboBox>
This DOES pick up the saved value in the ApplicationSettings.Default class, so the binding does work in that direction.
When the user picks a new selection it doesn't update the application settings class. Note that itdoes trigger the binding: the converter is invoked and works correctly. Furthermore, triggering the binding in the SelectionChanged event handler does not work either.
I've seen lots of things on the internet to try to fix it (re-order the XAML, use SelectedValue vs. SelectedItem, etc.), but nothing seems to work.
I have a workaround where I set the value on ApplicationSettings.Default directly in the SelectionChanged event handler and change the binding mode, but that seems like an ugly hack.
Any suggestions?
Thanks,
Terry