It took me an embarrassingly long amount of time to figure out why your program isn't working.
Basically if I am correct, your Character Class will look something like this:
public class Character
{
public string Name { get; set; }
public int Level { get; set; }
public int[] Agility { get; set; }
public int[] Strength { get; set; }
public int[] Stamina { get; set; }
public int[] Intelligence { get; set; }
}
The reason why the Datagrid isn't working with these stat properties as they are separate from each other. It doesn't know how to create rows based on several distinct properties.
What you really need, as Nathan Cooper pointed out before, is another class called Stat (or something similar) that can house each of these properties as ints. You then need a collection of these classes to bind your datagrid to.
Think about it like this. You currently have your data grouped vertically into columns. Datagrids are used to data being grouped into rows. So you need a collection of objects that represent a row.
I have taken the time to create an example application which will show the concept working.
The Character Class looks like this:
public class Character
{
public string Name { get; set; }
public int Level { get; set; }
public List<Stat> Stats { get; set; }
public Character()
{
}
public class Stat
{
public int Agility { get; set; }
public int Strength { get; set; }
public int Intelligence { get; set; }
public int Stamina { get; set; }
}
}
Here you can see I created a Stat class similar to what Nathan was talking about. Like I said this class will house the "rows" of the datagrid so the data can be grouped in a way that the datagrid can easily understand.
The XAML of the form looks like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ComboBox Margin="5,5,5,5" DisplayMemberPath="Name" Grid.Row="0" ItemsSource="{Binding Path=Characters}" SelectedItem="{Binding Path=SelectedCharacter}"></ComboBox>
<DataGrid Grid.Row="1" Margin="5,5,5,5" AutoGenerateColumns="True" ItemsSource="{Binding Path=SelectedCharacter.Stats}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Agility" Binding="{Binding Path=Agility}"></DataGridTextColumn>
<DataGridTextColumn Header="Strength" Binding="{Binding Path=Strength}"></DataGridTextColumn>
<DataGridTextColumn Header="Intelligence" Binding="{Binding Path=Intelligence}"></DataGridTextColumn>
<DataGridTextColumn Header="Stamina" Binding="{Binding Path=Stamina}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
I created a combobox that will select the character to display in the DataGrid. This characters stats are bound to the columns of the datagrid.
Lastly here is the ViewModel (not sure if you are using MVVM but you prolly should. anyway this code could go in the code behind with little changing required):
public class MainWindowViewModel:ViewModelBase
{
private IList<Character> _characters;
public IList<Character> Characters
{
get
{
return _characters;
}
set
{
_characters = value;
RaisePropertyChanged(()=>Characters);
}
}
private Character _character;
public Character SelectedCharacter
{
get
{
return _character;
}
set
{
_character = value;
RaisePropertyChanged(()=>SelectedCharacter);
}
}
public MainWindowViewModel()
{
InitializeCharacters();
}
private void InitializeCharacters()
{
Characters = new List<Character>();
SelectedCharacter = new Character();
Characters.Add(new Character
{
Name = "Tank",
Level = 3,
Stats = new List<Character.Stat>()
{
new Character.Stat()
{
Agility = 10,
Intelligence = 8,
Strength = 14,
Stamina = 16
},
new Character.Stat()
{
Agility = 11,
Intelligence = 9,
Strength = 16,
Stamina = 18
},
new Character.Stat()
{
Agility = 12,
Intelligence = 10,
Strength = 17,
Stamina = 20
}
}
});
Characters.Add(new Character
{
Name = "Healer",
Level = 4,
Stats = new List<Character.Stat>()
{
new Character.Stat()
{
Agility = 10,
Intelligence = 14,
Strength = 8,
Stamina = 10
},
new Character.Stat()
{
Agility = 11,
Intelligence = 16,
Strength = 9,
Stamina = 11
},
new Character.Stat()
{
Agility = 12,
Intelligence = 17,
Strength = 10,
Stamina = 13
},
new Character.Stat()
{
Agility = 14,
Intelligence = 20,
Strength = 10,
Stamina = 14
}
}
});
Characters.Add(new Character
{
Name = "Ranger",
Level = 6,
Stats = new List<Character.Stat>()
{
new Character.Stat()
{
Agility = 12,
Intelligence = 8,
Strength = 10,
Stamina = 8
},
new Character.Stat()
{
Agility = 14,
Intelligence = 9,
Strength = 11,
Stamina = 10
},
new Character.Stat()
{
Agility = 17,
Intelligence = 10,
Strength = 12,
Stamina = 11
},
new Character.Stat()
{
Agility = 18,
Intelligence =11,
Strength = 13,
Stamina = 12
},
new Character.Stat()
{
Agility = 20,
Intelligence = 12,
Strength = 15,
Stamina = 13
},
new Character.Stat()
{
Agility = 22,
Intelligence = 13,
Strength = 16,
Stamina = 13
}
}
});
}
}
Most of the space in the ViewModel is taken up by me creating dummy data, so feel free to delete it if you like. The important part is the creation of the SelectedCharacter and Characters Classes.
Here is a link to the project so you can see it in action. (excuse the shitty name I am bad at names)
https://docs.google.com/open?id=0B9JOiSJxT9vjZVl1SHd3UzBiZEE
Good Luck
U_U