我有以下情景:
1. 列表包含一年中的月份:
一个ComboBox,其ItemsSource绑定到Months列表,SelectedIndex绑定到属性Month,该属性是一个字符串。
当我在代码后台设置年份时,例如 Month = "May",这会正确地传播到 ComboBox,并访问 Month 的 getter,但是 ComboBox 没有显示“May”作为其选定的项目。 我想知道:这是 Silverlight 3 中的错误吗? 当我使用 Telerik 的 RadComboBox 时,它运行良好。
1. 列表包含一年中的月份:
public List<String> Months
{
get
{
return m_Months;
}
}
m_Months = new List<String>();
for (int i = 1; i <= 12; i++)
{
DateTime date = new DateTime(1900, i, 1);
m_Months.Add(date.ToString("MMM"));
}
一个ComboBox,其ItemsSource绑定到Months列表,SelectedIndex绑定到属性Month,该属性是一个字符串。
public string Month
{
get
{
return m_Month;
}
set
{
if (value != m_Month)
{
m_Month = value;
NotifyPropertyChanged("Month");
}
}
}
<ComboBox SelectedItem="{Binding Month, Mode=TwoWay}" ItemsSource="{Binding Months}" />
当我在代码后台设置年份时,例如 Month = "May",这会正确地传播到 ComboBox,并访问 Month 的 getter,但是 ComboBox 没有显示“May”作为其选定的项目。 我想知道:这是 Silverlight 3 中的错误吗? 当我使用 Telerik 的 RadComboBox 时,它运行良好。