private void drop(IDataObject dataObject) { if (dataObject == null) { return; } var data = dataObject.GetData(typeof(DraggableRowsBehavior.Data)) as DraggableRowsBehavior.Data; if (data == null) { return; } if (data.TargetIndex < 0 && Devices.Any()) // // don't allow invalid targets, but allow drop on an empty grid { return; } TsiFileViewModel srcFile = data.SenderDataContext as TsiFileViewModel; if (srcFile == null) { return; } DeviceViewModel selected = data.SelectedItems[0] as DeviceViewModel; int newIndex = Math.Max(0, data.TargetIndex); if (srcFile != this || !data.IsMove) { if (data.IsMove) { srcFile.removeDevice(selected); } var rawDevice = selected.Copy(true); insertDevice(newIndex++, rawDevice); } else { var movingAction = new Action <int, int>((oi, ni) => { _tsiFile.MoveDevice(oi, ni); _devices.Move(oi, ni); }); MovingLogicHelper.Move <DeviceViewModel>(_devices, new List <DeviceViewModel> { selected }, newIndex, movingAction); } SelectedDevice = selected; }
private void drop(IDataObject dataObject) { if (dataObject == null) { return; } var data = dataObject.GetData(typeof(DraggableRowsBehavior.Data)) as DraggableRowsBehavior.Data; if (data == null) { return; } if (data.TargetIndex < 0 && Mappings.Any()) // // don't allow invalid targets, but allow drop on an empty grid { return; } DeviceViewModel srcDevice = data.SenderDataContext as DeviceViewModel; if (srcDevice == null) { return; } // copy and sort selected items List <RowItemViewModel> selected = new List <RowItemViewModel>( data.SelectedItems .Cast <RowItemViewModel>() .OrderBy(s => srcDevice._mappings.IndexOf(s)) ); int newIndex = Math.Max(0, data.TargetIndex); if (srcDevice != this || !data.IsMove) { if (data.IsMove) { srcDevice.removeMappings(selected); } SelectedMappings.Clear(); foreach (var row in selected) { var rawMapping = (row.Item as MappingViewModel).Copy(true); insertMapping(newIndex++, rawMapping); } } else { var movingAction = new Action <int, int>((oi, ni) => { _device.MoveMapping(oi, ni); _mappings.Move(oi, ni); }); MovingLogicHelper.Move <RowItemViewModel>(_mappings, selected, newIndex, movingAction); } if (selected.Any()) { selected.Last().BringIntoView(); } }