I’m creating a map for an RPG game. The map is a grid with 12 columns and 13 lines totaling 156 locations:
<Border Grid.Row="0"
Grid.Column="0"
Style="{StaticResource MyBorder}">
<Image Source="{Binding MapBackground_1.ImageName, Converter={StaticResource FileToBitmapConverter}}"
Style="{StaticResource MyImage}" />
<Border Grid.Row="0"
Grid.Column="1"
Style="{StaticResource MyBorder}">
<Image Source="{Binding MapBackground_2.ImageName, Converter={StaticResource FileToBitmapConverter}}"
Style="{StaticResource MyImage}" />
</Border>
... up to 156
And I have 156 properties with their respective 156 backing fields:
public Location? MapBackground_1 { get => _mapBackground_1; set { _mapBackground_1 = value; OnPropertyChanged(); } }
public Location? MapBackground_2 { get => _mapBackground_2; set { _mapBackground_2 = value; OnPropertyChanged(); } }
... up to 156
And a method that sets the background image for each location:
public void SetImagesOfMap()
{
MapBackground_1 = CurrentWorld?.LocationAt(0, 0);
MapBackground_2 = CurrentWorld?.LocationAt(0, 1);
...
}
Is it possible to simplify the creation of properties with a List of Locations and the rest of the code?