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 09:54:49
 
 
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:
01431650
Views:
50
>>Hi Viv
>>
>>Thanks for taking the time to look into this.
>>
>>>
>>>Further to my original post *please* , *please* post the XAML for this - without it the discussion raging on this thread will not reach a resolution !
>>
>>I have posted the XAML in another reply.
>>
>>But this gets worse again. I am up to Chapter 4 in the book and opened a form from the CD samples. This form has 2 "Windows Forms Hosts" controls in it with the DateTime control embedded. Unfortunately the book does not explain how to do this but I found out using Google.
>>
>>The problem is that with this form (I added the 2 blue rectangles for alignment), the left alignment is correct for IDE and runtime. But the right side alignment is totally off as seen from this image:
>>
>>http://www.foxite.com/uploads/b29cf803-3dd1-424d-92fd-4768c0aeaac0.jpg
>>
>>I drew the red lines to show the alignment. Also the Quit button has the Bottom edge below where it is supposed to be. That I understand since the "Windows Forms Hosts" is only a container. I wish I could visually adjust the embedded control but that appears impossible. The only method appears to be to add code to manually resize the embedded control and "run it and see".
>>
>>However I cannot see why the right edges of each control are so badly off.
>>
>>Again here is the XML generated by VS (not by me):
>>
>>
>><Window x:Class="Selection.Window1"
>>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>>    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
>>    Title="Dates" Height="314" Width="373">
>>    <Grid>
>>    <Label HorizontalAlignment="Left" Margin="20,25,0,0" Name="label1" Width="35.63" Height="23.2766666666667" VerticalAlignment="Top">First</Label>
>>    <Label Height="23.2766666666667" HorizontalAlignment="Left" Margin="20,56,0,0" Name="label2" VerticalAlignment="Top" Width="52.63">Second</Label>
>>	<WindowsFormsHost Name="hostFirst" Margin="85,25,0,0" Height="23" VerticalAlignment="Top">
>>      <wf:DateTimePicker Name="first"/>
>>    </WindowsFormsHost>
>>    <WindowsFormsHost Name="hostSecond" Margin="85,56,63,0" Height="23.277" VerticalAlignment="Top">
>>	  <wf:DateTimePicker Name="second"/>
>>    </WindowsFormsHost>
>>    <Button Height="23" HorizontalAlignment="Left" Margin="20,100,0,0" Name="compare" VerticalAlignment="Top" Width="75" Click="compareClick">Compare</Button>
>>    <TextBox Margin="20,131,104,20" Name="info" TextWrapping="WrapWithOverflow" AcceptsReturn="False" IsReadOnly="True" TextChanged="info_TextChanged" />
>>    <Button Height="23.277" HorizontalAlignment="Right" Margin="0,56,0,0" Name="quit" VerticalAlignment="Top" Width="57" Click="quitClick">Quit</Button>
>>        <Rectangle Height="19" HorizontalAlignment="Left" Margin="85,0,0,0" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="60" Fill="Azure" />
>>        <Rectangle Height="19" HorizontalAlignment="Left" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="81" Fill="CornflowerBlue" />
>>    </Grid>
>></Window>
>>
>>
>>Basically I want some consistent way,( even a workaround will do), to get my forms looking the same in runtime as I design them in the VS IDE, using WPF in VS 2008. I don't want to have to "run the form and see" and make adjustments by trial and error as with more complicated forms that would soon become tedious.
>>
>>Thanks for your time.
>
>Hi,
>I think what's causing the problem here is the fact that the Window size is not neccessarily shown at exactly the right size at design time - probably because the IDE can't know what theme may be in place at runtime.

Since any theme applied is usually to the border and titlebar of a formI don't see how a theme will effect this as long as the controls are within the grid and the grid is within the form. Any theme effect will happen outside this area so I don't accept this explanation.

To avoid the controls running right to the edge of the form simply stop them running to the edge of the grid. Something like
<Grid Margin="4">
It is not the control at the edge of the form I am talking about. That was done purposely. It is the fact that the "Windows Forms Hosts" with the DateTime control in it that takes on a mind of its own and resizes at runtime. I thought the image and the red lines I had drawn were clear enough. The image clearly shows the "Windows Forms Hosts" control has un necessarily expanded to be a different width at runtime. That is totally wrong that I have to be forced to adjust the width using Trial and error to get a proper fit.

>
>As in the other reply try resizing the window to get an idea of how things behave - notice that the Grid (which has not specific size set) expands/contracts with the window.

If it does that it is doing it on its own. I never set any properties for it.

I think you are missing the point here. I showed in the image that the "Windows Forms Hosts" was resizing itself at runtime to a different size, which is not necessary.

All I want is some workaround from a more experienced WPF person, so that if I set a control's size in the IDE, unless I explicitly change it, it should maintain the same size at runtime, not change at will as is happening now - same as I would expect and do get using a windows forms app.

Bernard
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform