gpt4 book ai didi

c# - 将字典绑定(bind)到组合框

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:43 27 4
gpt4 key购买 nike

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

代码:

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" />

显示内容如下:

enter image description here

最佳答案

这似乎是已知的错误。这里有一些链接供您引用。我试过 this Silverlight sample对于 Windows 应用商店应用程序,我也只得到没有文本的白色项目。

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com