我正在尝试用一对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;
ComboBoxItem:
public class ComboBoxItem
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
正如您所见,我正在使用我的ResourceDictionary
插入Text
值。但是如果我以这种方式做,当我在运行时更改语言时,ComboBox
的内容不会改变。
因此,我想尝试在设计时(在XAML中)填充我的ComboBox
。
所以我的问题是:如何像上面那样用一对文本、值填充我的ComboBox
?