我有一个数据绑定组合框列出财务年度。用户从该组合中选择一个值,并从“客户”组合框中选择一个值,然后选择该财务年度的客户报告以供用户处理。尽管可以处理历史文档,但默认使用情况是处理刚刚完成的财政年度的报表,因此我想将组合框设置为默认值(当前)2011/2012,该值是FinancialYear的字符串属性实体。在wpf组合框中的默认值
我的XAML:
<ComboBox Canvas.Left="353"
Canvas.Top="18"
Height="23"
Name="cboFinancialYear"
Width="120"
DisplayMemberPath="FinancialYear1"
ItemsSource="{Binding}"
SelectedValuePath="FinancialYearID" />;
的Window_Loaded
方法背后我的代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
String thisYear = MainViewModel.GetCurrentFinancialYear();
lGFinanceEntities = new LGFinanceEntities();
// Load data into FinancialYears. You can modify this code as needed.
CollectionViewSource financialYearsViewSource = ((CollectionViewSource)(this.FindResource("financialYearsViewSource")));
ObjectQuery<FinancialYear> financialYearsQuery = this.GetFinancialYearsQuery(lGFananceEntities);
financialYearsViewSource.Source = financialYearsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
cboFinancialYear.SelectedItem = thisYear;
}
然而,这似乎并没有产生任何影响,并且所选项目在组合框中是在FinancialYear表中的第一年。
有人可以指出我做错了什么吗?我环顾四周,但组合框中的大多数默认值实现似乎都是“选择一年”排序的指令文本,而我想实际选择一个默认值。
你的ItemsSource是什么类型? – gaurawerma 2012-07-30 04:45:19
@gaurawerma嗯,有趣。 xaml应该有一个Source属性。我将它固定在下面,但仍然不起作用: 但它仍然不起作用 –
mcalex
2012-07-30 04:53:04
我的意思是什么是您的ItemsSource中的实体类型 – gaurawerma 2012-07-30 04:55:10