I have trouble to formulate the XAML string to link to a specific element in a multidimensional array.
The DataContext contains the following lines:
private String[] _OneDimension = { "[0]", "[1]" };
private String[][] _Jagged = { new String[] { "[0,0]", "[0,1]" }, new String[] { "[1,0]", "[1,1]" } };
private String[,] _TwoDimension = { { "[0,0]", "[0,1]" }, { "[1,0]", "[1,1]" } };
public String[] OneDimension { get { return _OneDimension; } }
public String[][] Jagged { get { return _Jagged; } }
public String[,] TwoDimension { get { return _TwoDimension; } }
The XAML contains the following lines:
<StackPanel>
<Button Content="{Binding OneDimension[1]}" Width="100" Height="50" />
<Button Content="{Binding Jagged[1][1]}" Width="100" Height="50" />
<Button Content="{Binding TwoDimension[1][1]}" Width="100" Height="50" />
</StackPanel>
The binding to OneDimension
and Jagged
work as expected. The binding to TwoDimension
does not work and appears to be wrong, however the XAML does not allow me to use the separator ,
so I do not know how to bind to a two dimensional array.
This:
<Button Content="{Binding TwoDimension[1,1]}" Width="100" Height="50" />
does not compile because the XAML gets interpreted as having two arguments for the Binding Constructor. Is there some way to escape the parser or is there another way of writing this that I am not aware of?
EDIT:
I just found out that it is possible to escape the separator like this
<Button Content="{Binding TwoDimension[1\,1]}" Width="100" Height="50" />
or just surround the argument with markers like this
<Button Content="{Binding 'TwoDimension[1,1]'}" Width="100" Height="50" />
However this line now leads to an exception: System.ArgumentException
{"Das Array war kein eindimensionales Array."} unfortunatelly C# installed itself in my native language - annoying as shit... so this roughly translates to {"The Array was not a onedimensionale Array."}
Is it actually impossible to bind multidimensional arrays?