/// <summary> /// ReorderBehavior Reordering Event Handler - Adjusts Entity Order and GroupPreferenceId of entities after reordering /// </summary> /// <param name="sender">Sender</param> /// <param name="e">ReorderingEventArgs</param> private void ReorderBehavior_Reordering(object sender, ReorderingEventArgs e) { //if there are no dragged Items reordering is redundant if (e.DraggedItems.Count().Equals(0)) { return; } #region Get Dragged Element //dragged Element MarketSnapshotPerformanceData draggedElement = e.DraggedItems.FirstOrDefault() as MarketSnapshotPerformanceData; //null Exception Handling if (draggedElement == null) { return; } #endregion #region Get Data Context //collection of MorningSnapshotData binded to the grid List <MarketSnapshotPerformanceData> dataContext = (e.SourceGrid.ItemsSource as ObservableCollection <MarketSnapshotPerformanceData>).ToList(); //null Exception Handling if (dataContext == null) { return; } #endregion #region Get Drag Drop Details //drag drop Indexes int dragIndex = dataContext.IndexOf(draggedElement); int dropIndex = e.DropIndex; //true if insertion is done after an element and False if it's done before the element bool isDropPositionAfter = DragDropPosition.Value == DropPosition.After; //check if the drop Index exceed the Count of List - item dropped after the last element bool isDropIndexExceedingCount = dropIndex >= dataContext.Count; #endregion #region Drag Location Parameters MarketSnapshotPreference dragBenchmarkDetails = new MarketSnapshotPreference() { EntityName = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityName, EntityReturnType = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityReturnType, EntityOrder = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityOrder, GroupName = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.GroupName, GroupPreferenceID = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.GroupPreferenceID }; #endregion #region Drop Location Parameters MarketSnapshotPreference dropBenchmarkDetails = new MarketSnapshotPreference() { EntityName = isDropIndexExceedingCount ? null : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.EntityName, EntityReturnType = isDropIndexExceedingCount ? null : dataContext.ElementAt(e.DropIndex).MarketSnapshotPreferenceInfo.EntityReturnType, EntityOrder = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.EntityOrder + 1 : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.EntityOrder, GroupName = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.GroupName : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.GroupName, GroupPreferenceID = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.GroupPreferenceID : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.GroupPreferenceID }; #endregion #region Managing discrepancies in drop location //if drop location is after the last element of same or another group the behavior picks the next element nevertheless bool isDragdropGroupSame = dragBenchmarkDetails.GroupPreferenceID == dropBenchmarkDetails.GroupPreferenceID; bool isDropEntityMisread = dropBenchmarkDetails.EntityOrder == 1 && isDropPositionAfter; bool isDropLastOfSameGroup = GetLastGroupPreferenceId(dataContext, dropBenchmarkDetails.GroupPreferenceID) == dragBenchmarkDetails.GroupPreferenceID && isDropEntityMisread; bool isDropLastOfOtherGroup = (!isDropLastOfSameGroup) && isDropEntityMisread; #endregion bool isDragWithinGroup = isDragdropGroupSame ? (!isDropLastOfOtherGroup) : isDropLastOfSameGroup; if (isDragWithinGroup) { UpdateParametersForSameGroupReordering(dataContext, dragBenchmarkDetails, dropBenchmarkDetails, isDropLastOfSameGroup); } else { UpdateParametersForDiffGroupReordering(dataContext, dragBenchmarkDetails, dropBenchmarkDetails, isDropLastOfOtherGroup); } }
/// <summary> /// ReorderBehavior Reordering Event Handler - Adjusts Entity Order and GroupPreferenceId of entities after reordering /// </summary> /// <param name="sender">Sender</param> /// <param name="e">ReorderingEventArgs</param> private void ReorderBehavior_Reordering(object sender, ReorderingEventArgs e) { // if there are no dragged Items reordering is redundant if (e.DraggedItems.Count().Equals(0)) { return; } #region Get Dragged Element // dragged Element CSTUserPreferenceInfo draggedElement = e.DraggedItems.FirstOrDefault() as CSTUserPreferenceInfo; // null Exception Handling if (draggedElement == null) { return; } #endregion #region Get Data Context // collection of CSTUserPreferenceInfo binded to the grid List <CSTUserPreferenceInfo> dataContext = (e.SourceGrid.ItemsSource as ObservableCollection <CSTUserPreferenceInfo>).ToList(); // null Exception Handling if (dataContext == null) { return; } #endregion #region Get Drag Drop Details // drag Drop Indexes int dragIndex = dataContext.IndexOf(draggedElement); int dropIndex = e.DropIndex; // true if insertion is done after an element and False if it's done before the element bool dropPositionIsAfter = DragDropPosition.Value == DropPosition.After; // check if the drop Index exceed the Count of List - item dropped after the last element bool dropIndexExceedsCount = dropIndex >= dataContext.Count; #endregion #region Drag Location Parameters CSTUserPreferenceInfo dragUserPreferenceInfo = new CSTUserPreferenceInfo() { ScreeningId = dataContext.ElementAt(dragIndex).ScreeningId, DataDescription = dataContext.ElementAt(dragIndex).DataDescription, UserName = UserSession.SessionManager.SESSION.UserName, ListName = dataContext.ElementAt(dragIndex).ListName, Accessibility = dataContext.ElementAt(dragIndex).Accessibility, DataPointsOrder = dataContext.ElementAt(dragIndex).DataPointsOrder, TableColumn = dataContext.ElementAt(dragIndex).TableColumn }; #endregion #region Drop Location Parameters CSTUserPreferenceInfo dropUserPreferenceInfo = new CSTUserPreferenceInfo() { ScreeningId = dropIndexExceedsCount ? null : dataContext.ElementAt(dropIndex).ScreeningId, DataDescription = dropIndexExceedsCount ? null : dataContext.ElementAt(e.DropIndex).DataDescription, UserName = UserSession.SessionManager.SESSION.UserName, ListName = dataContext.ElementAt(dragIndex).ListName, Accessibility = dataContext.ElementAt(dragIndex).Accessibility, DataPointsOrder = dropIndexExceedsCount ? dataContext.ElementAt(dropIndex - 1).DataPointsOrder : dataContext.ElementAt(dropIndex).DataPointsOrder, TableColumn = dataContext.ElementAt(dragIndex).TableColumn }; #endregion // update the data points order of list UpdateParametersForSameGroupReordering(dataContext, dragUserPreferenceInfo, dropUserPreferenceInfo, dropIndexExceedsCount); }
private void SignalFilters_ChildReordered(object sender, ReorderingEventArgs e) { Root.IsDataModified = true; }