use*_*889 5 c# silverlight-3.0
我有以下场景:
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"));
}
Run Code Online (Sandbox Code Playgroud)
1 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}" />
Run Code Online (Sandbox Code Playgroud)
当我从代码隐藏设置Year时,即Month ="May",这被正确地传播到ComboBox,并且访问了Month的getter,但是ComboBox没有显示'May'作为它的选择项.
我想知道:这是Silverlight 3中的一个错误吗?当我使用Telerik的RadComboBox时,它工作正常.
干杯,弗朗西斯
use*_*889 10
感谢您的回复.尝试过你的建议并获得相同的结果.然而,我刚刚有一个荷马辛普森时刻(Dôh!)并且发现我在ComboBox设置它的ItemsSource之前设置了月份.
但奇怪的是,RadComboBox正确地完成了所有工作.也许它会在ItemsSource更改时再次检索SelectedItem.
编辑:
好吧,我只是惊讶地从椅子上掉了下来.显然,SL3仍然有一些需要修复的错误.在下面的节目中大饱眼福......
这不起作用:
<ComboBox SelectedItem="{Binding Month, Mode=TwoWay}" ItemsSource="{Binding Months}" />
Run Code Online (Sandbox Code Playgroud)
这样做:
<ComboBox ItemsSource="{Binding Months}" SelectedItem="{Binding Month, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
看到微小的差异?只要我在XAML中的SelectedItem 之前设置ItemsSource ,一切都在世界上很好.Wowee,我从来不知道XAML是线性解析的!
| 归档时间: |
|
| 查看次数: |
7340 次 |
| 最近记录: |