I have a window app and it updates dynamically, an issue I have is removing the maxWidth and maxHeight set to the window, I must have a maxWidth and maxHeight in some scenarios as per the company requirements but at points I need to remove the max limits for other scenarios.
All I want to know is how to remove the maxWidth and maxHeight, I assume it is possible.
You can set the MaxWidth and MaxHeight property of a WPF window to double.PositiveInfinity which is the default value for both. This will remove any max constraint:
//store the current/previous value
double oldMaxWidth = this.MaxWidth;
//remove the constraint
this.MaxWidth = double.PositiveInfinity;
Related
How to make a ComboBox change its width based on content but make the popup list with items to be of constant width?
I've figured it out. I created a new ItemContainerStyle and set the width of items there, and have not specified the width for the ComboBox.
Say I have a Grid whose Width is set as Auto. Inside this grid I want to put a new grid that is a square. To do this I want the new grid's width and height to be equal. I thought I could just set the Width and Height to the Parent Grid's Width. The problem is, the Parent grid's width is double.NaN since it is set to auto.
My question, is there a way to get the ActualWidth of this parent grid, so that I know how wide it is? If not, is there another way to create a Rectangular Grid that fits inside the parent grid?
You have to use the property of ActualWidth
var width = LayoutRoot.ActualWidth;
I am not sure how well it works with windows phone 7 but see if this article helps you.
Is it possible to use WinForms layout engine to set up a form in such a way that the height is adjusted completely automatically to fit the content, but the width would be adjustable by the user?
As an example, consider the following somewhat contrived form:
TLP: TableLayoutPanel, with 1 row and 2 columns.
label1: Label, contained in the left column. Set Text to something long, AutoSize to false, Dock to Fill.
button1: Button, contained in the right column. Set AutoSize to true.
Now set the row to "AutoSize", the first column to "100%" and the second column to "AutoSize".
Finally, set the whole TLP to AutoSize true, AutoSizeMode to GrowAndShrink.
At this point, the TLP could reasonably be resized horizontally, but WinForms doesn't seem to allow this.
The idea is that the form containing this TLP would grow or shrink vertically based on the width, which the user can change by resizing the window as usual.
Hopefully you have got the solution by now. But in case anybody having a same query, You can set width of Maximum Size Property to the Actual Width of the Form and the Height of MaximumSize to 0.
This is entirely possible. To do this, you have to override SetBoundsCore on your form. In this you can then control the height such that it doesn't change when a resize might want it to. Just store the height you want it to be in a variable and then have your override always set it to that. This way, when you auto-size the height, you save the new height aware before setting form Height and SetBoundsCore will honour that new height.
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.
Is there a good way to limit the Auto Width of an element or Grid Column?
I want to limit the Auto Width only, but allow any user changes.
For example, I want to allow GridSplitter to arbitrarily resize the column, but the initial (Auto) Width should not exceed a specific value. Same for the elements -- I want to allow resizing, but limit the Width they have if never resized.
MaxWidth works exactly as opposite -- it does not affect Auto Width of Grid Columns (it might be a bug), but limits the resized width.
Is there any good solution that works for (almost) any element or Grid part?
Try binding the MaxWidth to the Width and use a IValueConverter to react to changes from Auto to specific values.
In the grid column set the width you want the column to start at. Any changes to the column width made by the user using the grid splitter will overwrite the width you start with.