我正在尝试将字典绑定到组合框,但是在UI上没有显示任何项,只有空白项被绑定。请找到下面的代码,让我知道我在做什么错?

码:

private Dictionary<string, string> _timeToExpirationValues =
new Dictionary<string, string>     { "< 15 Days", "15" },
                                   { "< 30 Days", "30" },
                                   { "< 60 Days", "60" },
                                   { "< 90 Days", "90" },
                                   { "< 1 year", "365" }};


        /// <summary>
        /// Gets or sets the filter settings data.
        /// </summary>
        /// <value>
        /// The filter settings data.
        /// </value>
        public Dictionary<string, string> TimeToExpirationValues
        {
            get { return _timeToExpirationValues; }
            set { SetProperty(ref _timeToExpirationValues, value); }
        }


XAML代码:

 <ComboBox Grid.Row="1" Grid.Column="1"
                                  ItemsSource="{Binding TimeToExpirationValues}"
                                  DisplayMemberPath="Key"
                                  SelectedValuePath="Value" />


显示内容如下:

最佳答案

这似乎是已知的错误。这是您的一些链接。我为Windows Store App尝试了this Silverlight sample,但我也只获得了没有文本的白色物品。

Binding a Dictionary to a WinRT ListBox

TargetException error in Binding - MSDN Forum

TargetException error in Binding to Dictionary<string, object> - Submitted Bug

关于c# - 将字典绑定(bind)到组合框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16333597/

10-17 01:13