private void CreateBoats() { foreach (IBoat boat in Boats) { BoatControl boatControl = new BoatControl(); Binding height = new Binding(nameof(BoatControl.BoatHeightProperty)) { Source = boat, Path = new PropertyPath("RowSpan") }; Binding width = new Binding(nameof(BoatControl.BoatWidthProperty)) { Source = boat, Path = new PropertyPath("ColumnSpan") }; Binding column = new Binding(nameof(ColumnProperty)) { Source = boat, Path = new PropertyPath("Column") }; Binding row = new Binding(nameof(RowProperty)) { Source = boat, Path = new PropertyPath("Row") }; Binding columnSpan = new Binding(nameof(ColumnSpanProperty)) { Source = boat, Path = new PropertyPath("ColumnSpan") }; Binding rowSpan = new Binding(nameof(RowSpanProperty)) { Source = boat, Path = new PropertyPath("RowSpan") }; Binding isSelected = new Binding(nameof(BoatControl.IsSelectedProperty)) { Source = boat, Path = new PropertyPath("IsSelected") }; Binding isEnabled = new Binding(nameof(BoatControl.ShowBoat)) { Source = boat, Path = new PropertyPath("ShowItem") }; boatControl.SetBinding(BoatControl.BoatHeightProperty, height); boatControl.SetBinding(BoatControl.BoatWidthProperty, width); boatControl.SetBinding(ColumnProperty, column); boatControl.SetBinding(RowProperty, row); boatControl.SetBinding(ColumnSpanProperty, columnSpan); boatControl.SetBinding(RowSpanProperty, rowSpan); boatControl.SetBinding(BoatControl.IsSelectedProperty, isSelected); boatControl.SetBinding(BoatControl.ShowBoatProperty, isEnabled); /// <summary> /// sets the first boat ontop of the board /// e.g. Boats[1] is the 2nd boat and there are 5 boats: 5 - 2 + 1 = 4 /// hence the 4th highest of all the boats, "+ 1" is to be ontop of the checkered tiles /// </summary> Panel.SetZIndex(boatControl, Boats.Count - Boats.IndexOf(boat) + 1); BoardGrid.Children.Add(boatControl); } }