public void BindGrids() { StateValueToFillColorConverter stateValueToFillColorConverter = new StateValueToFillColorConverter(); BindComputerGrid(); for (int c = 1; c < 11; c++) { for (int r = 1; r < 11; r++) { //Creates a black border that will take the size of the grid cell Border border = new Border { BorderThickness = new Thickness(1), BorderBrush = borderBrush, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; //Create a new Rectangle with a name of Column, Row and Fill of barkBlue Rectangle rect = new Rectangle { Name = $"{c - 1}, {r - 1}" }; //Creates a binding for the cell IsAlive property, sets converter to bool converter, and 2-way mode Binding newBinding = new Binding { Source = board.PlayerGrid.PlayerGrid[c - 1, r - 1], Path = new PropertyPath("GridState"), Converter = stateValueToFillColorConverter, Mode = BindingMode.TwoWay }; //Sets the binding to the retangle's fill property rect.SetBinding(Rectangle.FillProperty, newBinding); //Sets the border to the corresponding row and column Grid.SetColumn(border, c); Grid.SetRow(border, r); //Adds rectangle to the border border.Child = rect; //Adds the border to Play PlayerGrid.Children.Add(border); } } }
public CreateGame() { this.InitializeComponent(); createGrid.IsHidden = false; StateValueToFillColorConverter stateValueToFillColorConverter = new StateValueToFillColorConverter(); for (int c = 1; c < 11; c++) { for (int r = 1; r < 11; r++) { //Intilizes and sets the playCell object to a new cell as dead with it's corresponding row and column createGrid.PlayerGrid[c - 1, r - 1] = new Cell { GridState = CellState.Water, Location = $"{c-1}, {r-1}" }; createGrid.HiddenGrid[c - 1, r - 1] = new Cell { GridState = CellState.Water, Location = $"{c - 1}, {r - 1}" }; //Creates a black border that will take the size of the grid cell Border border = new Border { BorderThickness = new Thickness(1), BorderBrush = borderBrush, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; //Create a new Rectangle with a name of Column, Row and Fill of barkBlue Rectangle rect = new Rectangle { Name = $"{c - 1}, {r - 1}", Fill = water }; //Subsctibes Tapped Toggle_Cell event to the rectangle rect.Tapped += Set_Ship; //Creates a binding for the cell IsAlive property, sets converter to bool converter, and 2-way mode Binding newBinding = new Binding { Source = createGrid.PlayerGrid[c - 1, r - 1], Path = new PropertyPath("GridState"), Converter = stateValueToFillColorConverter, Mode = BindingMode.TwoWay }; //Sets the binding to the retangle's fill property rect.SetBinding(Rectangle.FillProperty, newBinding); //Sets the border to the corresponding row and column Grid.SetColumn(border, c); Grid.SetRow(border, r); //Adds rectangle to the border border.Child = rect; //Adds the border to Play CreationView.Children.Add(border); } } SetMusic(); }