Esempio n. 1
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();
            });
        }
Esempio n. 2
0
 public void CellValuePropertyChanged(object o, PropertyChangedEventArgs args)
 {
     _matrix[(o as CellValueVM).RowIndex, (o as CellValueVM).ColumnIndex] = Convert.ToDouble((o as CellValueVM).Value.Replace('.', ','));
     UpdatedMatrix?.Invoke();
 }