Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why does design time and runtime size differ?
Message
De
27/10/2009 08:09:51
 
 
À
26/10/2009 21:51:21
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Divers
Thread ID:
01431413
Message ID:
01431638
Vues:
41
>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. 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">
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform