[英]WPF ComboBox ItemsSource Binding on Dictionary not working
I'm having trouble with this binding and can't seem to get it working. 我在绑定时遇到麻烦,似乎无法正常工作。
xaml XAML
<telerik:RadComboBox
ItemsSource="{Binding ReminderTimes.Keys}"
SelectedItem="{Binding SelectedReminderTime,
UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>
c# 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. 我确实在属性get中设置了一个断点,但从未受到影响,我也不知道为什么。 Any input is appreciated. 任何输入表示赞赏。
Since your property "ReminderTimes" only has a getter, make sure you use Mode=OneWay. 由于您的媒体资源“ ReminderTimes”只有一个吸气剂,因此请确保使用Mode = OneWay。 By default, ItemsSource is a two way binding. 默认情况下,ItemsSource是双向绑定。
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. 我发现将datacontext设置为在ViewModel的树的更高位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.