我正在尝试将字典绑定到组合框,但在 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" />
显示的内容如下: