Esempio n. 1
0
        private void Rectangle_MouseLeftButtonUp(object sender, MouseEventArgs e)
        {
            Rectangle rect = sender as Rectangle;

            if (rect == null)
            {
                return;
            }

            if (!(rect_mouseLbuttonDown == rect))
            {
                return;
            }

            for (int i = 0; i < MaxSize; i++)
            {
                for (int j = 0; j < MaxSize; j++)
                {
                    if (rects[i, j] == rect)
                    {
                        this.RowValue = i + 1;
                        this.ColValue = j + 1;
                    }
                }
            }

            e.Handled = true;
            MatrixSelected?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 2
0
        public MatrixVM(Matrix matrix)
        {
            this._matrix             = matrix;
            _matrix.PropertyChanged += (o, e) => {
                RaisePropertyChanged(e.PropertyName);
            };

            SelectMatrix = new DelegateCommand(() => {
                MatrixSelected?.Invoke();
            });

            for (int i = 0; i < matrix.Rows; i++)
            {
                for (int k = 0; k < matrix.Columns; k++)
                {
                    CellValueVM cellValue = new CellValueVM();
                    if (double.IsNaN(matrix[i, k]))
                    {
                        //cellValue.Value = (i + k) % 2 == 0 ? "🗙" : "𐩒";
                        cellValue.Value = "🗙";
                    }
                    else
                    {
                        cellValue.Value = matrix[i, k].ToString();
                    }
                    cellValue.RowIndex    = i;
                    cellValue.ColumnIndex = k;
                    MatrixValues.Add(cellValue);
                    cellValue.PropertyChanged += CellValuePropertyChanged;
                }
            }


            AddRow = new DelegateCommand(() => {
                if (Rows < 10)
                {
                    matrix.SetNewSize(Rows + 1, Columns, true);
                    for (int i = 0; i < Columns; i++)
                    {
                        CellValueVM cellValue      = new CellValueVM();
                        cellValue.Value            = "0";
                        cellValue.RowIndex         = Rows - 1;
                        cellValue.ColumnIndex      = i;
                        cellValue.PropertyChanged += CellValuePropertyChanged;
                        MatrixValues.Add(cellValue);
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            AddColumn = new DelegateCommand(() => {
                if (Columns < 10)
                {
                    matrix.SetNewSize(Rows, Columns + 1, true);
                    for (int i = 0; i < Rows; i++)
                    {
                        CellValueVM cellValue      = new CellValueVM();
                        cellValue.Value            = "0";
                        cellValue.RowIndex         = i;
                        cellValue.ColumnIndex      = Columns - 1;
                        cellValue.PropertyChanged += CellValuePropertyChanged;
                        MatrixValues.Insert((Columns - 1) + ((Columns - 1) * i) + i, cellValue);
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteRow = new DelegateCommand(() => {
                if (Rows > 1)
                {
                    int tmp = Columns * Rows - 1;
                    matrix.SetNewSize(Rows - 1, Columns, false);
                    for (int i = 0; i < Columns; i++)
                    {
                        MatrixValues.RemoveAt(tmp);
                        tmp--;
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteColumn = new DelegateCommand(() => {
                if (Columns > 1)
                {
                    matrix.SetNewSize(Rows, Columns - 1, false);
                    for (int i = 0; i < Rows; i++)
                    {
                        Console.WriteLine("Count:" + MatrixValues.Count);
                        Console.WriteLine("index:" + ((Columns + (Columns * i)) + 1));
                        MatrixValues.RemoveAt(Columns + (Columns * i));
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteMatrix = new DelegateCommand(() => {
                DeletedMatrix?.Invoke();
            });
        }