Ejemplo n.º 1
0
        private void Button_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            Button button = sender as Button;

            if (button?.DataContext == null)
            {
                return;
            }
            GridCell cell = button.DataContext as GridCell;

            if (cell == null)
            {
                return;
            }
            GridLayoutViewModel vm = GridLayoutViewModel;

            if (vm == null)
            {
                return;
            }
            if (vm.SelectedCells.Contains(cell))
            {
                return;
            }
            vm.ClearSelection();
            vm.AddToSelection(cell);
        }
Ejemplo n.º 2
0
        private void GridLayout_Loaded(object sender, RoutedEventArgs e)
        {
            GridLayoutViewModel vm = GridLayoutViewModel;

            if (vm == null)
            {
                return;
            }
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            GridLayoutViewModel vm = new GridLayoutViewModel();

            this.GridLayout.DataContext = vm;
            this.DataContext            = vm;
            //int rows = 10;
            //int cols = 10;
            //vm.CreateGrid(rows, cols);
            //vm.MergeCells(0, 0, 2, 2);
            //vm.MergeCells(2, 2, 3, 3);
            //vm.MergeCells(5, 5, 2, 2);
            //vm.MergeCells(7, 7, 3, 3);
            int rows = 3;
            int cols = 3;

            vm.CreateGrid(rows, cols);
            vm.Merge(0, 0, 1, 2);
            //vm.MergeCells(1, 1, 1, 2);
            //vm.MergeCells(2, 0, 1, 3);
        }
Ejemplo n.º 4
0
        private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Button button = sender as Button;

            if (button?.DataContext == null)
            {
                return;
            }
            GridCell cell = button.DataContext as GridCell;

            if (cell == null)
            {
                return;
            }
            GridLayoutViewModel vm = GridLayoutViewModel;

            if (vm == null)
            {
                return;
            }
            vm.ClearSelection();
            if (vm.EditedCell != null)
            {
                vm.EditedCell.IsEditing = false;
            }
            cell.IsEditing = true;
            vm.EditedCell  = cell;

            IEnumerable <TextBox> textBoxes = Utils.FindVisualChildren <TextBox>(sender as DependencyObject);
            TextBox textBox = textBoxes.Cast <TextBox>().First();

            if (textBox != null)
            {
                textBox.Focusable = true;
                textBox.Focus();
            }
        }
Ejemplo n.º 5
0
        private void Button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Button button = sender as Button;

            if (button?.DataContext == null)
            {
                return;
            }
            GridCell gridCellVM = button.DataContext as GridCell;

            if (gridCellVM == null)
            {
                return;
            }
            GridLayoutViewModel vm = GridLayoutViewModel;

            if (vm == null)
            {
                return;
            }

            if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && vm.SelectedCells.Count > 0)
            {
                GridCell lastSelected = vm.SelectedCells[vm.SelectedCells.Count - 1];
                System.Drawing.Rectangle        extent    = System.Drawing.Rectangle.Union(lastSelected.CellExtent, gridCellVM.CellExtent);
                Dictionary <GridCell, GridCell> selectSet = new Dictionary <GridCell, GridCell>();
                foreach (GridCell cell in vm.SelectedCells)
                {
                    selectSet[cell] = cell;
                    extent          = System.Drawing.Rectangle.Union(cell.CellExtent, extent);
                }

                while (true)
                {
                    int selCount = 0;
                    foreach (GridCell cell in vm.GridElements)
                    {
                        if (cell.CellExtent.IntersectsWith(extent))
                        {
                            if (selectSet.ContainsKey(cell))
                            {
                                continue;
                            }
                            extent = System.Drawing.Rectangle.Union(cell.CellExtent, extent);
                            vm.AddToSelection(cell);
                            selectSet[cell] = cell;
                            selCount++;
                        }
                        else
                        {
                            cell.IsHighlighted = false;
                        }
                    }

                    if (selCount == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    vm.ClearSelection();
                }
                if (vm.SelectedCells.Contains(gridCellVM))
                {
                    gridCellVM.IsSelected    = false;
                    gridCellVM.IsHighlighted = false;
                    vm.RemoveFromSelection(gridCellVM);
                }
                else
                {
                    gridCellVM.IsSelected    = true;
                    gridCellVM.IsHighlighted = true;
                    vm.AddToSelection(gridCellVM);
                }

                if (vm.SelectedCells.Count == 0)
                {
                    return;
                }
            }
        }