private BudgetEditorDragDropHandler(BudgetEditor budgetEditor, BudgetEditorCategoryRow categoryRow, Point dragStartPosition)
 {
     this.BudgetEditor      = budgetEditor;
     this.DragType          = BudgetEditorDragTypes.Category;
     this.CategoryRow       = categoryRow;
     this.DragStartPosition = dragStartPosition;
 }
Exemplo n.º 2
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 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);
            }
        }
Exemplo n.º 4
0
 protected override void OnPreviewKeyDown(KeyEventArgs e)
 {
     if (e.Key == Key.Tab)
     {
         TextBox textBox = e.OriginalSource as TextBox;
         BudgetEditorCategoryMonth monthView   = FindParent(textBox);
         BudgetEditorCategoryRow   categoryRow = monthView.FindParent <BudgetEditorCategoryRow>();
         if (textBox != null && monthView != null && categoryRow != null)
         {
             if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
             {
                 e.Handled = NavigatePreviousCategoryMonth(textBox, categoryRow, monthView);
             }
             else
             {
                 e.Handled = NavigateNextCategoryMonth(textBox, categoryRow, monthView);
             }
         }
     }
     base.OnPreviewKeyDown(e);
 }
Exemplo n.º 5
0
        private bool NavigateNextCategoryMonth(TextBox textBox, BudgetEditorCategoryRow row, BudgetEditorCategoryMonth monthView)
        {
            if (!(this.DataContext is BudgetEditorViewModel editorViewModel))
            {
                return(false);
            }
            if (!(row.DataContext is CategoryRowViewModel rowViewModel))
            {
                return(false);
            }
            if (!(monthView.DataContext is CategoryMonthViewModel monthViewModel))
            {
                return(false);
            }

            var lastRow = rowViewModel.MasterCategory.Categories[rowViewModel.MasterCategory.Categories.Count - 1];

            if (rowViewModel == rowViewModel.MasterCategory.Categories.Last() && rowViewModel.MasterCategory == editorViewModel.MasterCategories.Last())
            {
                var nextCategoryMonth = FindNextCategoryMonth(editorViewModel, monthViewModel);
                var nextTextBox       = FindAmountBudgetedTextBox(nextCategoryMonth);
                if (nextTextBox != null)
                {
                    nextTextBox.Focus();
                    nextTextBox.BringIntoView();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Down);
                textBox.MoveFocus(request);
                return(true);
            }
        }
Exemplo n.º 6
0
        private bool NavigatePreviousCategoryMonth(TextBox textBox, BudgetEditorCategoryRow row, BudgetEditorCategoryMonth monthView)
        {
            if (!(this.DataContext is BudgetEditorViewModel editorViewModel))
            {
                return(false);
            }
            if (!(row.DataContext is CategoryRowViewModel rowViewModel))
            {
                return(false);
            }
            if (!(monthView.DataContext is CategoryMonthViewModel monthViewModel))
            {
                return(false);
            }

            if (rowViewModel == rowViewModel.MasterCategory.Categories.First() && rowViewModel.MasterCategory == editorViewModel.MasterCategories.First())
            {
                var previousCategoryMonth = FindPreviousCategoryMonth(editorViewModel, monthViewModel);
                var previousTextBox       = FindAmountBudgetedTextBox(previousCategoryMonth);
                if (previousTextBox != null)
                {
                    previousTextBox.Focus();
                    previousTextBox.BringIntoView();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Up);
                textBox.MoveFocus(request);
                return(true);
            }
        }