private BudgetEditorDragDropHandler(BudgetEditor budgetEditor, BudgetEditorMasterCategoryRow masterCategoryRow, Point dragStartPosition)
 {
     this.BudgetEditor      = budgetEditor;
     this.DragType          = BudgetEditorDragTypes.MasterCategory;
     this.MasterCategoryRow = masterCategoryRow;
     this.DragStartPosition = dragStartPosition;
 }
        private BudgetEditorCategoryRow GetLastCategory(BudgetEditorMasterCategoryRow masterCategoryRow)
        {
            int length    = masterCategoryRow.ItemContainerGenerator.Items.Count;
            var container = masterCategoryRow.ItemContainerGenerator.ContainerFromIndex(length - 1);

            return(container.FindChild <BudgetEditorCategoryRow>());
        }
        private bool IsFirstMasterCategory(BudgetEditorMasterCategoryRow masterCategoryRow)
        {
            var itemsControl = BudgetEditor.CategoryItemsControl;
            var container    = VisualTreeHelper.GetParent(masterCategoryRow);

            return(itemsControl.ItemContainerGenerator.IndexFromContainer(container) == 0);
        }
        private void CategoryDragOverEmptyBottomSpace()
        {
            var lastMasterCategory = GetLastMasterCategory();

            TargetMasterCategory = lastMasterCategory;
            InsertPosition       = lastMasterCategory.ItemContainerGenerator.Items.Count;
            DropTargetAdorner    = new DropTargetInsertAdorner(lastMasterCategory, DropTargetAdornerLayer, true);
        }
Beispiel #5
0
        private TextBox FindAmountBudgetedTextBox(CategoryMonthViewModel categoryMonth)
        {
            var masterCategory = categoryMonth.CategoryRowViewModel.MasterCategory;
            var category       = categoryMonth.CategoryRowViewModel;

            BudgetEditorMasterCategoryRow masterCategoryRow = CategoryItemsControl.ItemContainerGenerator.ContainerFromItem(masterCategory).FindChild <BudgetEditorMasterCategoryRow>();
            BudgetEditorCategoryRow       categoryRow       = masterCategoryRow.ItemContainerGenerator.ContainerFromItem(category).FindChild <BudgetEditorCategoryRow>();
            var categoryMonthControl = categoryRow.ItemContainerGenerator.ContainerFromItem(categoryMonth).FindChild <BudgetEditorCategoryMonth>();

            return(categoryMonthControl.FindName("AmountBudgetedTextbox") as TextBox);
        }
        private bool IsHalfwayOverHeader(BudgetEditorMasterCategoryRow masterCategoryRow, Point point)
        {
            var itemsPresenter = masterCategoryRow.FindChild <ItemsPresenter>();
            var headerHeight   = masterCategoryRow.RenderSize.Height - itemsPresenter.RenderSize.Height;

            if (point.Y > headerHeight * 0.66)
            {
                return(true);
            }

            return(false);
        }
        private BudgetEditorMasterCategoryRow GetPreviousMasterCategoryRow(BudgetEditorMasterCategoryRow masterCategoryRow)
        {
            var itemsControl = BudgetEditor.CategoryItemsControl;
            var index        = itemsControl.ItemContainerGenerator.IndexFromContainer(VisualTreeHelper.GetParent(masterCategoryRow));

            if (index >= 1)
            {
                var previousContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(index - 1);
                return(previousContainer.FindChild <BudgetEditorMasterCategoryRow>());
            }

            return(null);
        }
        private void CategoryDragOverMasterCategoryHeader(BudgetEditorMasterCategoryRow masterCategoryRow, Point masterCategoryRowPoint)
        {
            if (IsFirstMasterCategory(masterCategoryRow))
            {
                var categoryRow = masterCategoryRow.ItemContainerGenerator.ContainerFromIndex(0)?.FindChild <BudgetEditorCategoryRow>();
                if (categoryRow != null)
                {
                    TargetMasterCategory = masterCategoryRow;
                    InsertPosition       = 0;
                    DropTargetAdorner    = new DropTargetInsertAdorner(categoryRow, DropTargetAdornerLayer, false);
                }
            }
            else
            {
                if (IsHalfwayOverHeader(masterCategoryRow, masterCategoryRowPoint))
                {
                    var categoryRow = masterCategoryRow.ItemContainerGenerator.ContainerFromIndex(0)?.FindChild <BudgetEditorCategoryRow>();
                    if (categoryRow != null)
                    {
                        TargetMasterCategory = masterCategoryRow;
                        InsertPosition       = 0;
                        DropTargetAdorner    = new DropTargetInsertAdorner(categoryRow, DropTargetAdornerLayer, false);
                    }
                }
                else
                {
                    var previousMasterCategory = GetPreviousMasterCategoryRow(masterCategoryRow);
                    var lastCategory           = GetLastCategory(previousMasterCategory);
                    int length = previousMasterCategory.ItemContainerGenerator.Items.Count;

                    TargetMasterCategory = previousMasterCategory;
                    InsertPosition       = length;

                    if (length == 0)
                    {
                        DropTargetAdorner = new DropTargetInsertAdorner(previousMasterCategory, DropTargetAdornerLayer, true);
                    }
                    else
                    {
                        DropTargetAdorner = new DropTargetInsertAdorner(lastCategory, DropTargetAdornerLayer, true);
                    }
                }
            }
        }
        private void CategoryDragOverCategory(Point categoryControlPosition, BudgetEditorMasterCategoryRow masterCategoryRow, UIElement categoryContainer)
        {
            var categoryItemsControl            = BudgetEditor.CategoryItemsControl;
            BudgetEditorCategoryRow categoryRow = categoryContainer.FindChild <BudgetEditorCategoryRow>();
            var categoryRowPoint = categoryItemsControl.TranslatePoint(categoryControlPosition, categoryRow);

            InsertPosition       = masterCategoryRow.ItemContainerGenerator.IndexFromContainer(VisualTreeHelper.GetParent(categoryRow));
            TargetMasterCategory = masterCategoryRow;
            bool isTargetNextRow = categoryRowPoint.Y > categoryRow.RenderSize.Height * 0.66;

            if (isTargetNextRow)
            {
                InsertPosition++;
                DropTargetAdorner = new DropTargetInsertAdorner(categoryRow, DropTargetAdornerLayer, true);
            }
            else
            {
                DropTargetAdorner = new DropTargetInsertAdorner(categoryRow, DropTargetAdornerLayer, false);
            }
        }