I am binding an Image control to a property of an array element like so:
<Image Name="Image1" Source="{Binding ImageWpf}" ... />
and in the code behind:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Image1.DataContext = _monster.Genes[0];
// ...
}
The array is a property of an object which itself is a member of the window:
public partial class WindowGenes : Window
{
public Monster _monster;
// ...
}
this is the array-property from the Monster class:
public Gene[] Genes
{
get
{
Gene[] g = new Gene[9];
for (int i = 0; i < 9; i++)
{
var read = BitConverter.ToUInt32(_data, _startOffset + OFFSET_GENES + i * 4);
g[i] = Gene.CreateFromValue( read );
}
return g;
}
set
{
for (int i = 0; i < 9; i++)
{
var bt = BitConverter.GetBytes(value[i].Id);
Array.Copy(bt, 0, _data, _startOffset + OFFSET_GENES + i * 4, 4);
}
}
}
to complicate things further, the array is generated in the properties getter, because this is created from a byte-array which represents a save file. Meaning, each read/get creates another array.
The binding itself seems to work. When the window is loaded it shows the proper Image. But the images do not change. I know there is the IPropertyChanged-interface but where should i implement that and how? I mean it wouldn't make sense to implement that for the ImageWpf property because the arrays items themselves (and also the array) are changed and not just the ImageWpf property.