Uniform grid Rows and Columns
- by Carlo
I'm trying to make a grid based on a UniformGrid to show the coordinates of each cell, and I want to show the values on the X and Y axes like so:
_A_ _B_ _C_ _D_
1 |___|___|___|___|
2 |___|___|___|___|
3 |___|___|___|___|
4 |___|___|___|___|
Anyway, in order to do that I need to know the number of columns and rows in the Uniform grid, and I tried overriding the 3 most basic methods where the arrangement / drawing happens, but the columns and rows in there are 0, even though I have some controls in my grid. What method can I override so my Cartesian grid knows how many columns and rows it has?
C#:
public class CartesianGrid : UniformGrid
{
protected override Size MeasureOverride(Size constraint)
{
Size size = base.MeasureOverride(constraint);
int computedColumns = this.Columns; // always 0
int computedRows = this.Rows; // always 0
return size;
}
protected override Size ArrangeOverride(Size arrangeSize)
{
Size size = base.ArrangeOverride(arrangeSize);
int computedColumns = this.Columns; // always 0
int computedRows = this.Rows; // always 0
return size;
}
protected override void OnRender(DrawingContext dc)
{
int computedColumns = this.Columns; // always 0
int computedRows = this.Rows; // always 0
base.OnRender(dc);
}
}
XAML:
<local:CartesianGrid>
<Label Content="Hello" />
<Label Content="Hello" />
<Label Content="Hello" />
<Label Content="Hello" />
<Label Content="Hello" />
<Label Content="Hello" />
</local:CartesianGrid>
Any help is greatly appreciated. Thanks!