WPF expander size issue - wpf

I am using an ItemsControl to place n number of Expanders. My ItemsControl will be placed in a Grid with height 600 (for example). I want to make sure my ItemsControl will always occupy the entire available Height, to do so it can expand some of the Expanders.
What will be the best approach to do so?

One way would be to bind the Height and Width properties of your control to the parent's ActualWidth and ActualHeight properties

Related

WPF - getting the REAL width of a control

I want to set the MinWidth of a Grid ColumnDefinitions to the ActualWidth of a DataGrid inside it.
The main problem is the DataGrid has a (built-in) vertical scroller since its contents are many. So, the actual width is the size of its columns and some more, but not including the scroller.
What happens is that when I set the MinWidth, I get the rightmost column hidden behind the scroller.
I appreciate solving this both in the code and the XAML (just in order to learn).
Try putting the DataGrid into a Canvas and bind to the ActualWidth property of that instead.

UserControl Width is Nan while it's ActualWidth set to the Column it placed on

I have a UserControl, I do not set it's Width / Height, the UserControl has 2 TextBox inside a StackPanel.
when I place it in a Column where it's Width="Auto", the control stretches to fill the entire column, while the 2 TextBox maintain their Width (desire)
I want to keep the Control Width to it's Content Width, how to I do that ?
HorizontalAlignment="Left"
This will keep the Control from stretching based on the container which it resides and instead will expand based on its contents if the Width is set to Auto.
MSDN provides an overview on Alignment, Margins, and Padding which may be of assistance.

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.

WPF Window MinWidth depending on size of toolbar

Before asking this question I have looked at all related questions, but have not found anything relevant.
In my application I have toolbox style bar, which is basically stack panel with bunch of buttons. User may change which buttons are shown in toolbar.
Window width may be changed, but it can not be smaller then width of toolbar.
At first I was hoping to bind the MinWidth property to the StackPanel Width property and create converter that adds few pixels to Width of the StackPanel. The problem is that my converter does not get Width of StackPanel, just NaN as value :(
Unfortunately, StackPanel width is set to Auto and I can not change that.
Is there any way I can make my Window MinWidth dependable on Width of StackPanel?
Use ActualWidth, not Width.
Width is the requested width, or NaN for "Auto", ActualWidth is the, well, actual width after all the layout is calculated.

WPF - setting HorizontalAlignment= Stretch to Textbox in StackPanel

Why doesn't a textbox stretch to fill space in a stackpanel? Is this by design? In a grid, the textbox stretches as expected.
Yes, it's by design. The StackPanel will allocate the space the TextBox asks for. If you haven't set a width on the TextBox, it will require only enough width to fit its text.
Kent's answer seems right.
To still force override the StackPanel behavior, I think you'd need to dynamically compute-set the Width property of the contained elements OR some funky override of MeasureOverride. I'd rather use another layout manager/panel. Some things I noted..
The default value for HorizontalAlignment and VerticalAlignment properties of child elements is Stretch (if you don't specify one explicitly).
The StackPanel will stretch elements based on its Orientation property value. So
Orientation=Horizontal means all elements will be vertically stretched to max. Elements flow horizontally.
Orientation=Vertical means all elements will be horiz stretched to max. Elements flow vertically.
Unless explicitly specified, Width and Height of child elements are NaN. If you specify an explicit value, StackPanel will honor them over the Horiz and Vert Alignment settings.
The StackPanel itself has HorizontalAlignment and VerticalAlignment that adds a further layout twist. You can experiment with this example.
StackPanel
The default value is stretch for both
HorizontalAlignment and
VerticalAlignment of content that is
contained in a StackPanel.
HorizontalAlignment
When Height and Width properties are
explicitly set on an element, these
measurements take higher precedent
during layout and will cancel the
typical effects of setting
HorizontalAlignment to Stretch.
I needed items to be sized evenly, but stacked vertically.
I used a UniformGrid, and set the Columns property to 1. (tested with a TextBox, and it stretches like you want)

Resources