Ok, To summarize what I am doing, I am part of a college group that wants to develop a turn-based, grid-field, stratagy game for the Microsoft Surface. The question I have does not involve any issues with touch based control, so don't worry about that. This game will be developed for the Surface using WPF and .NET 3.5 Framework.
The game's battle system will be very similar to the playstyles to popular games like Fire Emblem, Final Fantasy Tactics, and Disgaea 2, Where all units will be placed on a grid-field which will represent thier position and will also be used for the Units movement and Attack Ranges.
Now, Seeing as this game will be heavily based on a grid, I figured the best way to do this is to use the standard System.Windows.Controls.Grid, and Define as many Rows and Columns as needed in the XAML code.
Example:
<Grid Background="{StaticResource WindowBackground}" x:Name="GridField" ShowGridLines="True" Width="1024" Height="768">
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32"/>
<ColumnDefinition Width="32"/>
<ColumnDefinition Width="32"/>
</Grid.ColumnDefinitions>
This code would create and show a 3x3 grid with each grid block being 32x32 in size.
Now, assume there is a fully developed class called Unit that will hold all the information to represent a Unit, including it's Name and the Image that represents this unit. For sake of Arguement, assume that the unit's image is the correct size and format to be correctly displayed when assigned to the grid.
For my team's current plan, we intend to represent all units currently on the field in an array in the C# code.
Example:
public Unit[,] allUnits = new Unit[3,3];
Where the [3,3] represents the number of columns and rows the grid has defined.
Now, normally to assign a individual item to the grid you would have to define the item position explictly saying something like:
Grid.Row = "1" Grid.Column = "1" Source = "{Binding Unit.Picture}"
Now I KNOW that is not correct syntax, but I really don't care for this method, and my example at least gives an idea on how it is handled.
So here is my question: Is there any way to directly databind my 2 Dimensional Array of Units to my Defined Grid without defining each and every element position? For Example: If there is a way to represent the grid itself as an array, such as GridField[1,2] would represent Grid.Row = "1" Grid.Column = "2" (<-That is possibly backwards), then all I would have to do is say GridField[1,2] = Unit[1,2].Picture or something similar to this.
I'm not sure there is a way to do this, so That is why I am asking about the best way to do this.
To Summarize: I want to know how to Directly bind my grid to my 2 dimentional array of units, so that the grid becomes a visable represention of the units in my array. I want to know how to do this without having to explicitly define every single Grid Block's content to point at the correct array position. I would prefer not having each unit define its position because that is the purpose of the 2 dimentional array, but if it is unavoidable so be it.
I'm hoping there is a feasable solution to this issue, because if there isn't the next step would involve me creating my own grid, which would be a pain.
I apologize for any spelling errors and for the length of this question but I wanted to make myself as clear as possable.
Thank you for your time and suggestions, FrostFlame64