Databinding combobox selected item to settings

Posted by Tuukka on Stack Overflow See other posts from Stack Overflow or by Tuukka
Published on 2010-04-01T15:52:56Z Indexed on 2010/04/01 15:53 UTC
Read the original article Hit count: 336

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#