コード例 #1
0
 private void SelectSpot(Spot spot)
 {
     if (_selectedSpots.Contains(spot))
     {
         _selectedSpots.Remove(spot);
         SpotButton selectedSpotButton = _grid.Children.Cast <SpotButton>().First(e => Grid.GetRow(e) == spot.Row && Grid.GetColumn(e) == spot.Column);
         selectedSpotButton.Background = Brushes.Gray;
     }
     else if (_selectedSpots.Count < 5)
     {
         _selectedSpots.Add(spot);
         SpotButton selectedSpotButton = _grid.Children.Cast <SpotButton>()
                                         .First(e => Grid.GetRow(e) == spot.Row && Grid.GetColumn(e) == spot.Column);
         selectedSpotButton.Background = Brushes.ForestGreen;
     }
     else
     {
         MessageBox.Show("Mozesz wybrac max 5 miejsc.");
     }
 }
コード例 #2
0
        private Grid CreateView()
        {
            var              mainGrid = new Grid();
            SpotButton       spotButton;
            ColumnDefinition col;
            RowDefinition    row;

            for (int i = 0; i < _room.RowNumber; i++)
            {
                row        = new RowDefinition();
                row.Height = GridLength.Auto;
                mainGrid.RowDefinitions.Add(row);
            }

            for (int i = 0; i < _room.ColumnNumber; i++)
            {
                col       = new ColumnDefinition();
                col.Width = GridLength.Auto;
                mainGrid.ColumnDefinitions.Add(col);
            }


            var iterator = _room.Spots.GetEnumerator();

            while (iterator.MoveNext())
            {
                if (iterator.Current.IsAvailable != 2)
                {
                    spotButton                  = new SpotButton(iterator.Current);
                    spotButton.Command          = SelectSpotCommand;
                    spotButton.CommandParameter = iterator.Current;
                    Grid.SetColumn(spotButton, iterator.Current.Column);
                    Grid.SetRow(spotButton, iterator.Current.Row);
                    mainGrid.Children.Add(spotButton);
                }
            }


            return(mainGrid);
        }