Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why does design time and runtime size differ?
Message
From
29/10/2009 05:33:19
 
 
To
28/10/2009 18:57:43
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:
01432175
Views:
35
>>
>>Again - I suggest you try working using something other than a Grid as the top-level container.
>
>How would I do that? I am using VS and this grid is what is created when I opt for a new WPF project.

Delete it (either in the designer or in XAML) and replace it with the top-level control of your choice. (This is an *editor* we're talking about)

>
>> The XAML you are using is not something that would commonly be used - the Grid has no Rows or Columns defined and the positioning of each control in the entire form is solely governed by it's own Alignment and Margin settings
>
>Common or not, this is what VS generates for me, not, as I have already explained many many times, my XAML. Are you saying that when I want to create a new WPF project in VS, it generates code that is NOT commonly used?

Well certainly no more common than the many other options available. Just because WPF supplies it as a default doesn't mean you can't change it to an Element more suited to your needs.

>This is what I cannot understand.

As previously - normally a Grid contains Row and Column definitions. WPF obviously doesn't know the number or position or the Rows/Columns you may require - it's up to you to add them.

>
>I am not using the GRID as a preference but VS is creating the code for me
>I am not generating this XAML that is not commonly used. VS is doing that for me when I add any object.
>I am not explicitly setting the width/height of anything. VS is doing that for me.

Sorry - you are right about Height/Width. With a Grid, for some controls where it makes sense, WPF will supply default values. I guess it's making a best guess at interpreting your intentions on a control by control basis. For example for a Button it supplies a Width and Height, for a TextBox or ListBox is just supplies the Height leaving the Width to float.
Regardless, with experience, it's a trivial matter to check and edit these settings in XAML.

If you're using a Grid then try just adding a button and dragging it around within the Grid whilst watching the Properties window - you'll see how WPF tries to guess you're intentions by changing the HorizontalAlignment, VerticalAlignment and Margin properties to effectively dock the button to the closest edges. After moving then the arrows in the designer window give you a visual representation of how these are set. Obviously you can override these by changing values in the Properties sheet or editing the XAML..

In the end, the runtime representation *will* exactly follow the XAML specification. But until you become comfortable with interpreting/adjusting the settings (either in the Properties tab or in the XAML) I'm afraid that you will, as I did, find the process frustrating.

I'd suggest that you read as much as possible about the WPF layout system *before* attempting to use it.

>
>All I am trying to do is design a simple form visually, and have it look the same at design and run time.
>
>
>and, I agree, working out how the interaction between these two affects the final positioning and size of a UIElement is not the simplest part of XAML
>>
>>If you really want to exactly control the positioning and size of every object then use a Canvas instead of a Grid - but that would defeat the whole point of using the WPF UI.....
>
>I will have to read up on Canvas.

It will give you what you appear to want - controls of fixed size and position. But you'll probably find it too restrictive because you will have no equivalent of WinForms docking and anchoring available. And it really is not intended for this type of use.....

>
>Bernard
Previous
Reply
Map
View

Click here to load this message in the networking platform