我遵循法典
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var entities = new DemoEntities();
var depts = entities.Depts.ToList(); // entity framwork dept table
CollectionViewSource cvs = (CollectionViewSource)CollectionViewSource.GetDefaultView(depts);
}
}
我的用意是把收集工作捆绑在XAML的以下窗口资源中:
<Window.Resources>
<CollectionViewSource x:Key="Departments"/>
</Window.Resources>
使用
CollectionViewSource collectionViewSource = this.FindResource("Departments") as CollectionViewSource;
However while executing following line of code
CollectionViewSource cvs = (CollectionViewSource)CollectionViewSource.GetDefaultView(depts);
它是个例外,唯一的例外是:
{"Unable to cast object of type System.Windows.Data.ListCollectionView to type System.Windows.Data.CollectionViewSource ."}
有些人可以帮助我,提供如何创建收集资料。 采用背后代码的观点?