internal void HandleDrop(BudgetEditorDragDropHandler dropInfo)
        {
            if (dropInfo.DragType != BudgetEditorDragTypes.Category)
            {
                throw new InvalidOperationException();
            }

            if (this.DataContext is MasterCategoryRowViewModel viewModel)
            {
                var categoryRow = dropInfo.CategoryRow.DataContext as CategoryRowViewModel;
                if (viewModel.MasterCategory.Categories.Contains(categoryRow.Category))
                {
                    categoryRow.Category.SetSortOrder(dropInfo.InsertPosition);
                    categoryRow.Category.Model.SaveChanges();
                }
                else
                {
                    viewModel.MasterCategory.Categories.Add(categoryRow.Category);
                    categoryRow.Category.SetSortOrder(dropInfo.InsertPosition);
                    categoryRow.Category.Model.SaveChanges();
                }

                viewModel.Categories.ForceSort();
            }
        }
Ejemplo n.º 2
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            var position = e.GetPosition(this);

            if (position.X <= CategoryColumnWidth)
            {
                _dragHandler = BudgetEditorDragDropHandler.CreateFromEvent(this, e);
            }
            else
            {
                _dragHandler?.DestroyDragAdorner();
                _dragHandler = null;
            }
        }
Ejemplo n.º 3
0
        internal void HandleDrop(BudgetEditorDragDropHandler dropInfo)
        {
            if (dropInfo.DragType != BudgetEditorDragTypes.MasterCategory)
            {
                throw new InvalidOperationException();
            }

            if (this.DataContext is BudgetEditorViewModel viewModel)
            {
                var masterCategoryRow = dropInfo.MasterCategoryRow.DataContext as MasterCategoryRowViewModel;
                masterCategoryRow.MasterCategory.SetSortOrder(dropInfo.InsertPosition);
                viewModel.BudgetModel.SaveChanges();

                viewModel.MasterCategories.ForceSort();
            }
        }
Ejemplo n.º 4
0
 protected override void OnPreviewMouseMove(MouseEventArgs e)
 {
     if (_dragHandler != null && e.LeftButton == MouseButtonState.Pressed && !_dragHandler.IsDragging)
     {
         var newPoint = e.GetPosition(this);
         var distance = Point.Subtract(newPoint, _dragHandler.DragStartPosition);
         if (distance.Length > 4.0)
         {
             if (_popupButton != null)
             {
                 _popupButton.IsPopupOpen = false;
                 _popupButton             = null;
             }
             _dragHandler.StartDrag();
             _dragHandler.DestroyDragAdorner();
             _dragHandler = null;
         }
     }
 }