Neighbouring DataGrid controls overlap

Oct 15, 2008 at 11:24 AM
Hi!

I'm iterating over a C# object's property list with C#, and am filling up a Grid column with a Label in the first column, and an editing control appropriate to the property in the second column.  The editing control gets a TwoWay data binding to the object's property. 

The idea have been to use a WPF DataGrid for properties that are List<something>.

On my test source object I have an IList<string> property followed by an IList<SillyClassWithOneField> property (where SillyClassWithOneField is a class with a single string property).

The IList<SillyClassWithOneField> DataGrid shows up with the correct values, but the DataGrid for the IList<string> property is hidden behind the other DataGrid.

The Grid is created like this:
   Grid grid = new Grid { Margin = new Thickness(3) };
   grid.ColumnDefinitions.Add(
new ColumnDefinition { Width = GridLength.Auto });
   grid.ColumnDefinitions.Add(
new ColumnDefinition { Width = new GridLength(100, GridUnitType.Star) });

Each step in the iteration over the properties do the following:
      grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
      AddLabel(grid, info, currentRow, 0);
      AddForm(grid, proxy, info, currentRow++, 1);

The label creation code of AddLabel, is:
   Label label = new Label { Content = value, VerticalContentAlignment = VerticalAlignment.Center };
   grid.Children.Add(label);
   Grid.SetRow(label, row);
   Grid.SetColumn(label, column);
("column" is 0 here)

The AddForm method looks like this:
private static void AddForm(Panel grid, object op, SomeProperty someProperty, int row, int column)
{
   Control control = GetControlForOperatorProperty(someProperty, op);
   grid.Children.Add(control);
   Grid.SetRow(control, row);
  Grid.SetColumn(control, column);
}

Does anyone know what I can do to avoid this overwrite?

Thanx!
Oct 15, 2008 at 11:29 AM
One thing I've tried to do to fix this, is to set the VerticalAligment property on the DataGrid controls, like this:
   DataGrid datagrid = new DataGrid();
   datagrid.VerticalAlignment =
VerticalAlignment.Stretch;

But setting the VerticalAlignment had no effect that I could see.
Oct 23, 2008 at 3:38 PM
Just to conclude this thread: this is a non-issue.

The mistake was mine, a cut'n paste error in the test object I used as the source object in data bindings (for the curious: I had two IList<T> properties, and the cut'n paste error caused setting the second property to clear out the first property).