Hi,
I have a xam data grid in Page1 and other in Page2 . i need to drag records from one grid and drop to other grid,using MVVM pattern in WPF.
Any Sample Applications would help Thanks.
hi jerovsek
i am also stuck in same problem so can you please share your code snippet with me
Thanks,
Atul
Thanks Matt .
ObservableCollection leagues = ndr.DataPresenter.DataSource as ObservableCollection;
worked out exactly as per our requirement.
HI,
If you are using the DataRecordPresenter you could get the viewmodel collection from that object's DataPresenter.DataSource property, Code Snippet:
ObservableCollection leagues = ndr.DataPresenter.DataSource as ObservableCollection; (probably bestway)
or you could get it from the Application.Current.Resources.
Code Snippet:
VM vm = Application.Current.Resources["vm"] as VM;
or you could get it from the Windows resources.
Code Snippet: Vm vm = Application.Current.Windows[0].Resources["vm"] as Vm;
Sincerely, Matt Developer Support Engineer
Matt,
I have Implemented events as below for XAMDataGRID
DataRecordPresenter dp; DataRecordPresenter dragOver; private void DragSource_DragStart(object sender, Infragistics.DragDrop.DragDropStartEventArgs e) {
dp = Utilities.GetAncestorFromType(e.DragSource as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter;
}
//This is giving me the Dragged element and the item i need to Drop
private void DragSource_Drop(object sender, Infragistics.DragDrop.DropEventArgs e) {
dragOver = Utilities.GetAncestorFromType(e.DropTarget as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter; Employee targetElement = dragOver.DataRecord.DataItem as Employee ; Employee sourceElement = dp.DataRecord.DataItem as Employee ; }
The Issue is i have seperate viewmodels for each drag & drop windows and i am not able to identify the view model of the drop window.
I can just create an instance of the viewmodel like
DropVm vm = new dropVM(); and drop my target element into my observablecollection property , But
our requirement is i can drag from a source and drop into any view which accepts my object. So i need to identify the dropTarget(it's view model).
Hi Matt,
Do we need to shift to XAM GRID for achieving Drag Drop Functionality b/w two Windows. Do we have any work around If not then we amy shift from xam data grid to xam grid. Please advice .