Can I set a custom MinWidth for an ApplicationView? - c#

Can I set custom ApplicationView MinWidth in my app?
Or Can I disable 500,320 and other, just set MinWidth like my current width?

Short answer, no. The user can always size a view down to the min width (and any size above it). If you don't specify the 320px min in the manifest, you'll default to 500px. If you set 320px, then the user can resize anywhere down to 320. There isn't any way to set a value in between 320 and 500.

Related

Why winform control size can't change according to my input value

i am buling a project with vs2022 winform on .net-framework4.8.
when i add a label(any control) control to windows form,i can cange control side by mouse as i like,it working fine.but if i change side by change size directly,then the return size didn't change according to my input value.
for example, my original size is 267x36
if i want to change height to 30, the return value become 223x25, and the size and location on windows form also abnormal,looks like both change automatic.
even i try to select two control, and use vs2022 button "make them same side",the second control also return a wrong size.enter image description here
i am using a laptop with 150% scaling and screen resolution 2560x1600
picture1,original size
picture2,return size2
picture3,windows form 3
It's because AutoSize is set to true by default for labels. Disabling AutoSize will let you control the size manually.

Why is the ListBox's DesiredSize.Width always zero?

I am creating a custom control in C#, and want to have a grid cell that contains a ListBox, which can be hidden or shown as desired. Hiding it is easy, I just set the Width to zero, however when I want to show it, I need to know the width that the ListBox would like to use.
I thought that DesiredSize.Width would give me this vale, but it's always zero, even after calling Measure(). Here is the code I'm using to show the ListBox...
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
_lb.Width = _lb.DesiredSize.Width;
Any ideas how I find the desired width?
If your ListBox is in the cell of a grid, give that grid column a name. Then in code, you can access the .ActualWidth property of that grid column and use that value to set the width of your ListBox.
That assumes of course that the width of your grid column is not set to Auto, because that would still give you a 0 value.
_lb.Width = myGridColumn.ActualWidth
You might need to subtract a little bit from the column width to make your control fit nicely.
EDIT
One thing that I've found is that the ListBox must have items added to it before it will return anything other than 0 when it is measured.
string myItem = "Don't ask for a bath in Athabaska";
_lb.Items.Add(myItem);
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double width = _lb.DesiredSize.Width;
As long as the ListBox has already been added to the window/usercontrol/grid, the above code returns a value of 227.53 for the width variable; using my defaults for font family and size.
If the ListBox has not been added to the window, or it doesn't have any items in it, it will return 0 for the .DesiredSize.Width property.
Also, if the .Visibility property is set to Collapsed instead of Hidden, the width will be 0.
Don't set the width to 0 when starting. Leave the width alone initially, set the .Visibility to Hidden. It will render to the needed width, but won't be shown. Then you can measure it and start playing around with the width.

Get WPF control height when it is set 'Auto'

I need get a WPF control height for calculate my next control margin top, but when I try get control height with textbox1.height, this is return 'Auto' and not numbers
What can I do for get control height, when it is set 'Auto'?
You should try this:
textBox1.ActualHeight
Remarks (by #Viv)
just make sure when you query for textBox1.ActualHeight, you do it once the control is Loaded. You're going to get 0.0 if you check ActualHeight before it's setup properly

How to change .net chart width to %100

How can I set the width of an asp:chart to be 100% the width of the page?
The chart width attribute does not like percentages.
Another solution would be to check the current resolution, how to get that from .net?
You can try using the Request.Browser.ScreenPixelsWidth property.

Read width value in runtime

When I read the width value of my GridColumn I get the default value set in xaml (640 pixels). But the column is much wider than that in runtime because it stretches according to the width of the browser. In runtime I want to scale some of my controls to match that but when I read the value of my column it still gives me the default value 640. Until I actually resize the column with a gridsplitter the correct value get through. Anyone know how I can get the REAL width of the column during runtime without me having to resize it first?
Double a = this.Column1.Width.Value; // Gives me the default value of 640 while the column is much wider than that.
Try
Double a = this.Column1.ActualWidth.Value;

Categories