Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why does design time and runtime size differ?
Message
From
27/10/2009 21:06:35
 
 
To
27/10/2009 20:24:08
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01431413
Message ID:
01431805
Views:
43
Bernard,

Your ComboBox has not shrunk. If you look carefully at your screenshots, you'll see that the left side of your two windows (IDE vs Runtime) are not lined up (look at the left edges of the TextBox and ComboBox). If you line up those left TextBox and ComboBox edges, I'm 99.999% sure that the right edges of the ComboBox in the two windows will be lined up.

It's the TextBox that has grown ... and that is because the TextBox does *not* have a Width specified, whereas you *have* specified a Width for the Combo. Ditto for the Buttons. Your top button has a Height specfied, whereas your bottom button does not ... that's why your bottom button has grown in height.

It's all very logical if you examine it closely.

~~Bonnie


>Thanks Viv, I will.
>
>As you explain it, by default, unless I explicitly set a width property, the control will expand.
>This occurs because the control is in the grid which is in the form.
>So if no explicit width is set for the grid, it expands to the form widthand the same with the controls, which is why the button in my example appears "anchored" to the form's edges.
>
>This I can understand and accept.
>
>However yesterday I was testing another simple form and now certain controls like the ComboBox are shrinking at runtime.
>
>See the image here:
>http://www.foxite.com/uploads/4f293999-336e-4cb9-8719-d4706297608c.jpg
>
>and the XAML for this form:
>
><Window x:Class="WpfApplication2.Window1"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    Title="Window1" Height="201" Width="386">
>    <Grid>
>        <TextBox Height="23" Margin="24,27,134,0" Name="textBox1" VerticalAlignment="Top" />
>        <Button HorizontalAlignment="Right" Margin="0,27,53,0" Name="button1" Width="75" Height="23" VerticalAlignment="Top">Button</Button>
>        <ComboBox Margin="24,71,0,69" Name="comboBox1" HorizontalAlignment="Left" Width="206" />
>        <Button HorizontalAlignment="Right" Margin="0,71,53,69" Name="button2" Width="75">Button</Button>
>    </Grid>
></Window>
>
>
>If you have the time, the project is also here zipped up:
>http://www.foxite.com/uploads/99375930-8ab3-48ac-b51c-2d308037d932.zip
>
>The combobox in question has a width property explicitly set to 206:
>
><ComboBox Margin="24,71,0,69" Name="comboBox1" HorizontalAlignment="Left" Width="206" />
>
>
>However, as the image shows, the combo resizes itself at runtime to not expand but to actually shrink which is quite different to what you have said so far.
>
>You explained the growing of controls which I understood (although this concept of NOT having default properties is quite different from anything else). But now I also have controls shrinking on me.
>
>In fact as you can see from the image, the form (alignment and size) looks perfect at design time but look what happens at runtime. It is all screwed up with some controls growing and some shrinking.
>
>I am at a loss to find some consistent behaviour here. Either a control shrinks or grows. What is happening with WPF here?
>
>Bernard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform