views:

299

answers:

2

I store user specified settings using application settings properties and databinding. It has been working fine, until i want user selected to font for combobox. Databinding between user settings and combobox not working. I want to store font family name.

App.XML
<Application.Resources>
    <ResourceDictionary>
        <properties:Settings x:Key="Settings" />
    </ResourceDictionary>               
</Application.Resources>

Window.XML

<ComboBox Name="Families" ItemsSource="{x:Static Fonts.SystemFontFamilies}"
  <!-- This line -->
  SelectedItem="{Binding Source={StaticResource Settings}, Path=Default.Font, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
              Margin="57,122,199,118">
        <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
        </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

Settings: font String User Arial

A: 

In what way isn't it working? Is an exception thrown, is the project not compiling, or is the setting is not getting saved?

Don't forget that you must expressly save settings once they are modified. For this reason, you might do better to bind to an ICommand that applies and saves the setting, rather than to the setting directly, or add a "save" button that is bound to such a command.

Jay
The settings are not getting saved/loaded. I am using Properties.Settings.Default.Save(); to save settings. Below is little demo that has checkbox (that is working) and combobox that is not working.www.tlcube.com/files/cfgdemo.zip
Tuukka
@Tuukka I probably won't be able to look at this until sometime over the weekend; maybe someone else will be able to look today.
Jay
A: 

Adding SelectedValuePath="Source" solve this problem.

Tuukka