I have a custom GridView like control made of a Grid panel with several controls in each row (All of them from System.Windows.Controls).
The user requested that the row Height will grow unrestricted with the control’s content. I’m having a problem to maintain the size of all the controls in each row with relation to the highest one.
I’m trying to one-way bind the Height of all the controls in each row to the RowDefenition ActualHeight property. but it is not working as I expect it to work (Each control keeps it’s own size to the minimum)
Any help will be appreciated, thanks.
Here is the code where I’m trying to bind:
RowDefinition rowDef = new RowDefinition();
cellsGrid.RowDefinitions.Add(rowDef);
rowDef.Name = "gvRow" + cellsGrid.RowDefinitions.Count;
cellsGrid.Children.Add(controlToAdd);
Grid.SetRow(controlToAdd, rowIndex);
Grid.SetColumn(controlToAdd, columnIndex);
Binding bindH = new Binding("ActualHeight");
bindH.Mode = BindingMode.OneWay;
bindH.Source = rowDef;
BindingOperations.SetBinding(controlToAdd,RowDefinition.HeightProperty, bindH);
controlToAdd.TabIndex = (totalTabIndex + 1); totalTabIndex++;
cell.CellElement = controlToAdd;
cell.EndEdit += new GridViewCell.GridViewEditHandler(cell_EndEdit);
Try setting your Control’s
VerticalAlignmenttoStretch, so it expands to fill all available space.Also, I don’t think
RowDefinitionhas anActualHeightproperty, so the binding is probably evaluating to nothing. You’d need to bind to theActualHeightof your control, however that value isn’t know until after it’s been Rendered. I suppose you could useDispatcher.Invoketo run something after the controls have been rendered, figure out which is the tallest control in the row, and set all item to be that height.