【发布时间】:2013-02-27 18:23:32
【问题描述】:
我正在尝试用一对 String, Value 填充 ComboBox。我在后面的代码中这样做了:
listCombos = new List<ComboBoxItem>();
item = new ComboBoxItem { Text = Cultures.Resources.Off, Value = "Off" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.Low, Value = "Low" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.Medium, Value = "Medium" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.High, Value = "High" };
listCombos.Add(item);
combo.ItemsSource = listCombos;
组合框项:
public class ComboBoxItem
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
如您所见,我使用ResourceDictionary 插入Text 值。但是如果我这样做,当我在运行时更改语言时,ComboBox 内容不会。
所以我想尝试在设计(在 XAML 中)填写我的 ComboBox。
所以我的问题是:我怎样才能用上面的一对 Text, Value 填充我的ComboBox?
【问题讨论】: