/// <summary> /// Occurs whwn any active border will selected. /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> private void SeatsBlock_BorderSelected(SelectableGrid arg1, SelectableGrid.ActiveBorder arg2) { BorderSelected?.Invoke(this, arg2); }
/// <summary> /// Filling rect of grid with a cells. /// </summary> /// <param name="startX"></param> /// <param name="startY"></param> /// <param name="width"></param> /// <param name="height"></param> protected void FillGridRect(int startX, int startY, int width, int height) { // Drop if init process not possible. if (OnElementIstiniation == null) { MessageBox.Show("Error: OnElementIstiniation event has no subscribers." + " Initialization not possible."); return; } #region Apply block active background if (SelectebleBlocks) { var activeBackplate = new ActiveBorder() { Parent = grid, //DebugLabel = debugLog, direction = ActiveBorder.Direction.Horizontal, x = startX, y = startY, Background = SelectedGridBackground, FromSize = 5, ToSize = 5, ZOrder = 0, OnClickHandler = delegate(object sender, MouseButtonEventArgs e) { // Update data. Active = this; // Inform subscribers. GridSelected?.Invoke(this); } }; activeBackplate.UpdateLayout(); Grid.SetRowSpan(activeBackplate.UI, height * 2); Grid.SetColumnSpan(activeBackplate.UI, width * 2); //activeBackplate.UI.Margin = new Thickness(-5, -5, -10, -10); activeBackplate.UI.Margin = new Thickness(0, 0, -5, -5); // Add grid that will block glitching selecting of the block during fast mouse moves. Grid overlay = new Grid() { Background = Brushes.Transparent }; grid.Children.Add(overlay); Grid.SetColumn(overlay, startX + 1); Grid.SetRow(overlay, startY + 1); Grid.SetRowSpan(overlay, height * 2); Grid.SetColumnSpan(overlay, width * 2); } #endregion #region Set active borders to columns if (SelectebleColumns) { for (int i = startX; i < (startX + width) * 2 + 2; i += 2) { var abm = new ActiveBorder() { Parent = grid, direction = ActiveBorder.Direction.Vertical, x = i, y = startY + 1, Background = SelectedBorderBackground }; // Inserting new column into the grid. abm.OnClickHandler = delegate(object sender, MouseButtonEventArgs e) { // Log //MessageBox.Show("Column " + abm.x + " inserting."); // Inform subscribers. BorderSelected?.Invoke(this, abm); }; abm.UpdateLayout(); Grid.SetRowSpan(abm.UI, height * 2 - 1); } } #endregion #region Set active borders to rows if (SelectebleRows) { for (int i = startY; i < (startY + height) * 2 + 2; i += 2) { var abm = new ActiveBorder() { Parent = grid, direction = ActiveBorder.Direction.Horizontal, x = startX + 1, y = i, Background = SelectedBorderBackground }; // Instrting new row into the grid. abm.OnClickHandler = delegate(object sender, MouseButtonEventArgs e) { // Log //MessageBox.Show("Row " + abm.y + " inserting."); // Inform subscribers. BorderSelected?.Invoke(this, abm); }; abm.UpdateLayout(); Grid.SetColumnSpan(abm.UI, width * 2 - 1); } } #endregion #region Insiniate elements to grid's cells. for (int y = startY; y < height; y++) { for (int x = startX; x < width; x++) { // Create seat UI. var seat = OnElementIstiniation.Invoke(x, y); // Append it to the gris. grid.Children.Add(seat); Grid.SetColumn(seat, x * 2 + 1); Grid.SetRow(seat, y * 2 + 1); } } #endregion }