简体   繁体   中英

WPF ComboBox ItemsSource Binding on Dictionary not working

I'm having trouble with this binding and can't seem to get it working.

xaml

<telerik:RadComboBox
    ItemsSource="{Binding ReminderTimes.Keys}"
    SelectedItem="{Binding SelectedReminderTime, 
                           UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>

c#

 public Dictionary<string, int> ReminderTimes
 {
     get { return ReminderTimesManager.GetReminderTimes(); }
 }

I did put a breakpoint in the properties get and it's not getting hit ever and I have no idea why. Any input is appreciated.

Since your property "ReminderTimes" only has a getter, make sure you use Mode=OneWay. By default, ItemsSource is a two way binding.

ItemsSource="{Binding ReminderTimes.Keys, Mode=OneWay}"

It was a stupid error. I found out that the datacontext was being set higher up the tree to a property in my ViewModel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM