I want to bind TextBlocks to a Modell. But it does not work and I have no idea why.
class GameModel : INotifyPropertyChanged {
string[] _teamNames;
...
public string teamName(int team)
{
return _teamNames[team];
}
public void setTeamName(int team, string name)
{
_teamNames[team] = name;
OnPropertyChanged("teamName");
}
protected void OnPropertyChanged(string name) {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
And the code which creates the TextBoxes
for (int currCol = 0; currCol < teams; currCol++) {
TextBlock teamNameBlock = new TextBlock();
Binding myNameBinding = new Binding();
myNameBinding.Source = myGame;
myNameBinding.Path = new PropertyPath("teamName", currCol);
myNameBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
teamNameBlock.SetBinding(TextBlock.TextProperty, myNameBinding); //The name of the team bind to the TextBlock
...
}