public PosConfigVM(IDashboardCellConfig cellConfigInput)
 {
     // clone the cellConfigInput
     if (cellConfigInput is LinePlotCellConfig lineCellConfig)
     {
         cellConfig = new LinePlotCellConfig(lineCellConfig);
     }
     else
     {
         cellConfig = cellConfigInput;
     }
     NotifyPropertyChanged("RowIndex");
     NotifyPropertyChanged("ColumnIndex");
     NotifyPropertyChanged("RowSpan");
     NotifyPropertyChanged("ColumnSpan");
     NotifyPropertyChanged("CellWidthMode");
     NotifyPropertyChanged("CellHeightMode");
     NotifyPropertyChanged("CellWidth");
     NotifyPropertyChanged("CellHeight");
     NotifyPropertyChanged("CellMinWidth");
     NotifyPropertyChanged("CellMinHeight");
     NotifyPropertyChanged("CellHorAlignMode");
     NotifyPropertyChanged("CellVertAlignMode");
     NotifyPropertyChanged("CellBackgroundStr");
     NotifyPropertyChanged("CellForegroundStr");
 }
 public void AddDashBoardCell(IDashboardCellConfig dashboardCellConfig)
 {
     if (dashboardCellConfig == null)
     {
         return;
     }
     if (dashboardCellConfig.GetType().FullName == typeof(LinePlotCellConfig).FullName)
     {
         // Add a line plot User Control to the Cell Container
         LinePlotCellUC linePlotCellUC = new LinePlotCellUC((LinePlotCellConfig)dashboardCellConfig);
         linePlotCellUC.Changed += new EventHandler <EventArgs>(Changed);
         CellsContainer.Children.Add(linePlotCellUC);
     }
     SyncRowColDefinitionsWithCells();
 }
        public void SyncRowColDefinitionsWithCells()
        {
            List <DashboardCellPosition> cellPositions = new List <DashboardCellPosition>();

            // iterate through each cell in the cells container
            for (int cell_iter = 0; cell_iter < CellsContainer.Children.Count; cell_iter++)
            {
                ICellUC cellUC = (ICellUC)CellsContainer.Children[cell_iter];
                IDashboardCellConfig  dashboardCellConfig = cellUC.GetDashboardCellConfig();
                DashboardCellPosition cellPosition        = dashboardCellConfig.CellPosition_;
                // manipulate cell position to avoid cell position conflicts by pushing the cell position down by one row
                if (cellPositions.Exists(x => x.RowIndex_ == cellPosition.RowIndex_ && x.ColIndex_ == cellPosition.ColIndex_))
                {
                    // get the maximum row Index
                    int maxRowIndex = (from pos in cellPositions select pos.RowIndex_).Max();
                    //modify the rowIndex to avoid duplicates
                    cellPosition.RowIndex_ = maxRowIndex + 1;
                    cellUC.GetDashboardCellConfig().CellPosition_ = cellPosition;
                }
                cellPositions.Add(cellPosition);
            }

            int maxRows = 0;
            int maxCols = 0;

            if (cellPositions.Count > 0)
            {
                maxRows = (from pos in cellPositions select pos.RowIndex_).Max() + 1;
                maxCols = (from pos in cellPositions select pos.ColIndex_).Max() + 1;
            }

            // Add adequate number of row and column definitions
            // Find rows deficit
            int rowDeficit = maxRows - CellsContainer.RowDefinitions.Count();
            int colDeficit = maxCols - CellsContainer.ColumnDefinitions.Count();

            // Do addition or deletion of row definitions for Row Grids
            if (rowDeficit > 0)
            {
                // add deficit rows
                for (int i = 0; i < rowDeficit; i++)
                {
                    CellsContainer.RowDefinitions.Add(GetNewRowDefinition());
                }
            }
            else if (rowDeficit < 0)
            {
                // delete excess rows
                for (int i = 0; i < -rowDeficit; i++)
                {
                    CellsContainer.RowDefinitions.RemoveAt(0);
                }
            }

            if (colDeficit > 0)
            {
                // add deficit columns
                for (int i = 0; i < colDeficit; i++)
                {
                    CellsContainer.ColumnDefinitions.Add(GetNewColDefinition());
                }
            }
            else if (colDeficit < 0)
            {
                // delete excess columns
                for (int i = 0; i < -colDeficit; i++)
                {
                    CellsContainer.ColumnDefinitions.RemoveAt(0);
                }
            }
        }
 public CellPosChangeWindow(IDashboardCellConfig cellConfig)
 {
     InitializeComponent();
     posConfigVM = new PosConfigVM(cellConfig);
     CellPosChangeForm.DataContext = posConfigVM;
 }