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 below
class with my IMyInterface Implemented
public class ClassName: IMyInterface
My IMyInterface
public interface IMyInterface: ICloneable, INotifyPropertyChanged
{
string FirstName{ get; set; }
string LastName { get; set; }
bool IsSelected { get; set; }
bool IsDefault { get; set; }
}
Collection
public class ClassNameCollection: ObservableCollection<ClassName>
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 events
private 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;
e.Index = source.Count() - 1;
e.NewCount = source.Count();
e.Handled = true;
}
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 below
DataGridCollectionViewSource dataGridCollectionView = new DataGridCollectionViewSource();
dataGridCollectionView.CreatingNewItem += OndataGridCollectionViewCreatingNewItem;
dataGridCollectionView.CommittingNewItem += OndataGridCollectionViewCommittingNewItem;
dataGridCollectionView.Source = itemSource;
var bind = new Binding { Source = dataGridCollectionView };
MyViewsManagerDataGrid.SetBinding(ItemsControl.ItemsSourceProperty, bind);
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.