Binding WPF combobox to a user settings property

前端 未结 2 1294
攒了一身酷
攒了一身酷 2021-01-23 14:20

I\'ve a combobox in WPF with 4 static values in it:



        
2条回答
  •  -上瘾入骨i
    2021-01-23 14:54

    Since you don't add strings, but ComboBoxItems to your ComboBox, you would also have to set its SelectedValuePath property:

    
        Alt
        Shift
        Ctrl
        Win
    
    

    Alternatively add strings to the ComboBox, and use SelectedItem instead of SelectedValue:

    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    ...
    
        Alt
        Shift
        Ctrl
        Win
    
    

    Note also that since WPF 4.5 you may write the Binding like this:

    SelectedItem="{Binding Path=(properties:Settings.Default).KeyModifier, Mode=TwoWay}"
    

提交回复
热议问题