DataGridCollectionViewSource

DataGridCollectionViewSource

本文介绍了通用控制帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我创建的控件有一个Interface(IMyInterface)和一个IEnumerable类型的ItemsSource。在运行时,ItemsSource将被赋予Collection类型(ObservableCollection,List或任何其他集合类型),类型如下所示 带有我的IMyInterface的类已实现Hi all,I was creating a control that has a Interface ("IMyInterface") and a ItemsSource of type IEnumerable. on run time the ItemsSource will be assigned with the Collection (ObservableCollection, List or any other collection type) with class type as belowclass with my IMyInterface Implementedpublic class ClassName: IMyInterface 我的IMyInterfaceMy IMyInterfacepublic interface IMyInterface: ICloneable, INotifyPropertyChanged { string FirstName{ get; set; } string LastName { get; set; } bool IsSelected { get; set; } bool IsDefault { get; set; } } 收藏Collectionpublic class ClassNameCollection: ObservableCollection<ClassName> 这样我就可以将集合类型转换为我的接口类型并进行一些操作,如添加/排序或删除等,但我使用Xceed DataGrid我使用DataGridCollectionViewSource将我的ItemsSource属性绑定到DataGrid 。我已触发以下事件so that i can type cast the collection to my interface type and do some manipulcation like Add/Sort or Remove etc., but i am using Xceed DataGrid i am binding my ItemsSource property to DataGrid using DataGridCollectionViewSource. and i have triggered the following eventsprivate void OndataGridCollectionViewCreatingNewItem(object sender, DataGridCreatingNewItemEventArgs e) { e.NewItem = duplicateItem; e.Handled = true; } private void OndataGridCollectionViewCommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e) { List<IMyInterface> source = e.CollectionView.SourceCollection as List<IMyInterface>; if (source == null) return; //source.Add(e.Item as IManageView); e.Index = source.Count() - 1; e.NewCount = source.Count(); e.Handled = true; } OndataGridCollectionViewCommittingNewItem中的我试图将ItemSource输入到List< imyinterface>但Actualy它失败了( e.CollectionView.SourceCollection是一个IEnumerable类型,例如 Xceed [ ^ ]他们是类型自从列表实现IEnumerable接口以来,它实现了它们正在使用直接集合。但在我的情况下我使用的是IMyInterface 类型的集合。 我对DataGrid的绑定ItemsSource peoperty在下面in OndataGridCollectionViewCommittingNewItem Event i am trying to type case the ItemSource to List<imyinterface> but Actualy it was failing (the e.CollectionView.SourceCollection is a IEnumerable type, As give in the example by Xceed[^] they are type casting it since List Implements IEnumerable Interface. in the example they are using the direct Collection. but in my case am using a collection of type IMyInterface).My binding ItemsSource peoperty to DataGrid was belowDataGridCollectionViewSource dataGridCollectionView = new DataGridCollectionViewSource(); dataGridCollectionView.CreatingNewItem += OndataGridCollectionViewCreatingNewItem; dataGridCollectionView.CommittingNewItem += OndataGridCollectionViewCommittingNewItem; dataGridCollectionView.Source = itemSource; var bind = new Binding { Source = dataGridCollectionView }; MyViewsManagerDataGrid.SetBinding(ItemsControl.ItemsSourceProperty, bind); 我从xceed论坛得到了帮助 Xceed [ ^ ]当我实现它时,示例给出了无效。请给我一个解决方案。i have got help from the xceed forum Xceed[^] the example give was not working when i implement it. please provide me with a solution.推荐答案你应该与创建它的人交谈 - Xceed - 他们应该提供技术支持,并且会比我们更了解他们的产品。如果他们不这样做,那么找另一个供应商并要求退款! 如果他们编写代码,他们会更好地理解我们 - 所以我'从那里开始,而不是在这里。当然,除非你没有付钱 - 在这种情况下他们可能不会和你说话,我们也不会...You should talk to the people who created it - Xceed - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!If they wrote the code, they will understand it better that we would - so I'd start there, not here. Unless of course, you haven't paid for it - in which case they probably won't talk to you, and neither would we...改变了绑定类型并实现了另一个方式arround。changed the binding type and implemented the other way arround. 这篇关于通用控制帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 12:58