autosize height of gridcontrol in list - winforms

I've got a winforms application, using devexpress library. In this application I have an overview form with a list of datagrids (gridview controls of devexpress). The number of rows is dynamic, so is the number of datagrids shown. The grids are programatically added to a panel on the form.
The width of the grids need to scale with the width of the form. I managed to do that by setting the property docking to "top". The height of the grids should scale based on the rows inside. But I can't make this happen.
How can I add a grid to the panel (or form) with width set to 100% and height based to content of the grid?

Refer this - Calculate the "perfect" size/height of a Grid
The height of the grid content can be calculated via the ViewInfo
object. Follow approach from the How to change the Grid's height
according to the total height of its rows example.

Related

WPF: Set Control Height to Fill Grid Row Height

A WPF Grid control with 3 row and 3 columns. The Height of the Row in question is set to Auto. In the first two cells I have two controls with dynamic heights. In the third cell, I have another control I want to be automatically set to stretch within the Grid cell. I have tried VerticalAlignment="Stretch", but that simply sets Grid Row Height equal to control's height. What are my options here?
Not sure what kind of control you are using in Cell 3, but most of the WPF controls will automatically stretch to fit inside the Grid cell. The row height of your grid will be set by the height of the controls in Cells 1 and 2.
If you are using some kind of custom control where the default behavior for height is different, you can set Height="Auto".
If that doesn't work either, you can do a data binding to get the actual height of the control in either cell 1 or 2. Set the Height property of your control in Cell 3 to the following:
Height="{Binding ActualHeight, ElementName=MyControlNameFromCell1, Mode=OneWay}"
EDIT
Another way that might be more robust is to do a data binding for the Height of the row. So instead of using "Auto" for the height of the row, use the data binding shown above.

How can the width of a chart in wpf be adjusted?

I am using the chart control from the WPF Toolkit. My question is simple, when my chart is displayed, the column is expanded to the width of the screen.
Is there a way to specify a maximum width? Thanks in advance.
You can specify a width explicitly via the Width property, or allow an element to expand up to a certain size via the MaxWidth property. These properties are common to all UI elements, not just charts.
See the FrameworkElement documentation.

Silverlight - Setting width of inner control based on width of container control

I have a peculiar requirement related to setting width of controls in silverlight. Generally when UI renders in Silverlight, width of container control is calculated based on widths of child controls. I have a requirement where layout of the application can change drastically. One of the scenarios is that I have a Grid cotaining listboxes in each column. These column can have several user controls. Now I want to set width of user controls to expand as much as possible to stretch for width of listbox control. Is there some way to do this? If I set fixed width of user controls, it could leave some area blank on UI or horizontal scroll in listbox may appear. If I set "Auto" width of user control, there could be some unused space in UI. Is there any way to deal with this issue?
Set the HorizontalAlignment of your usercontrols to System.Windows.HorizontalAlignment.Stretch. Note that you should leave your Width unset if you do this, as it takes precedence over HorizontalAlignment.

Make Silverlight ListBox always fill 100% of available height

I have a grid in Silverlight 3. The height of the grid row is set to "Auto". I have a ListBox in one of the grid cells. I want this listbox to fill 100% of the available space, even if it does not have enough items to do so. Currently, I have the ListBox height set to "Auto", and it will expand as items are added, and display a scroll bar when it reaches the size of the cell.
Any help is appreciated.
Set the vertical alignment on the Listbox, and remove the grid height being Auto, that is going to restrict the growth to what is absolutely needed.
VerticalAlignment = "Stretch"

How to place a long Grid in a WPF Layout Container?

When I place a Datagrid in a WPF Grid Layout container, the datagrid lengthens the Grid Layout.
I want it to occupy only the space available on screen.
Make sure your Grid.ColumnDefinition or Grid.RowDefinition's Width or Height is not set to Auto. If you set it to a fixed size or a star size then the row/column should not resize.
If you're still having problems a code sample would be useful.
You should place your Datagrid into a ScrollViewer, and the ScrollViewer into your Grid cell.
the grid is placed inside a tabitem.
I tried the scrollviewer. but the only thing that happens:
the scrollviewer gets as large as the too long datagrid.
as the tabitem can vary in height, I would rather not like to specify a fixed height for the grid.

Resources