Frustrated trying to position controls in a xaml window.

M

moondaddy

I'm trying to position controls in a window and am having a very difficult
time. I want all the controls to be anchored top/left so when I do the
final resizing of the window, all the controls sit in the same position.
However, as I place controls toward the right side of the form, the left
alignment changes to right, and the margin changes from ##,##,0,0 ##,##,##,0
to 0,##,##,0. so to position the control just as I want, I have to
painfully edit he margin values. In some cases, when the control is on the
right side of the form and the control has the value of ##,##,0,0, the left
margin is not what I would expect and the control repositions its self in a
place that doesn't make sense. Also the widths keep changing on me. This
is a royal pain.



What am I doing wrong?



Thanks.
 
W

Walter Wang [MSFT]

Hi,

I'm not sure if I've fully understood your question. Are you referring to
the Visual Studio 2008's XAML designer here? Have you tried Expression
Blend 2?

Also, please refer to "Alignment, Margins, and Padding Overview"
(http://msdn2.microsoft.com/en-us/library/ms751709.aspx) for more concept
on the positioning of WPF elements.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

moondaddy

Using expression is not an option right now.

I have a window or usercontrol which has a grid in it. in the grid, I
wanted to place a bunch of controls such as texboxes, combo boxes, etc. If
I want to position them in rows (4 across and 3 down.), first I set the
controls to:
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,0,0,0"

then I drag them into position. The controls on the right side will
automatically be reset to HorizontalAlignment="Right" which is really
annoying and make formatting UIs very time consuming.

Thanks.
 
W

Walter Wang [MSFT]

Hi,

I see your points here. However, I think the designer is trying to make a
guess that the elements at the right half side of the container will have
"Right" horizontal alignment so that they can stick to the right side when
the container is being resized.

Actually, I would suggest you to manually edit the XAML code first to
declare the columns and rows for the Grid; after that, when you drag & drop
elements on the Grid, the designer will automatically set
column/row/columnspan/rowspan of them and will not change the alignments.

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

moondaddy

Thanks Walter. I did that, however, when vs changes these properties to
it's best guess, it also changes the behavior when the window is resized, so
once again, I loose control of what I'm trying to do. I'm using a canvas
now and don't have the problem anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top