Hard to do exact positioning.
I've just learned the basics of WPF and XAML but I find it very hard to do exact positioning in my programs.
I've found out that you can use a Canvas and then use the item.SetValue(Canvas.LeftProperty, double); -function to place things, but thats a real hassle. Adding another canvas inside a canvas with exact layout doesn't work at all.
I'm looking for the easiest way to place things X% from the left (relative from the usercontrols left edge, not the windows) with a width of Y%, i want my programs to work in fullscreen on all resolutions.
[668 byte] By [
Chimme] at [2007-12-23]
You are going in the wrong direction IMHO.
You should use Panels (or a Grid witch also descends from Panel). Then use Margins or Padding.
Best regards,
Thomas Andersen
What is wrong? The way i'm doing it or should i not do absolute positioning at all?
It's a game i'm making so exact positioning is very important.
Anyway, i solved the any-resolution problem, it was just to add a <ViewBox> as root-element in my window. :)
% positioning is only possible with Grid using the * unit. I've shown a quick example of this below.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock>50%</TextBlock>
<TextBlock Grid.Column="1">25%</TextBlock>
<TextBlock Grid.Column="2">25%</TextBlock>
</Grid>
Bringing this thread back alive...
I'm working on a physicengine for my game but i need some advice before i continiue. 
If i use a System.Windows.Shapes.Polygon for my gameobjects, the location of all the points will be relative to where the polygon was created, not to where it is at the current moment. Look at the following code:
| Polygon p = new Polygon(); p.Points.Add( new Point(30, 30));p.Points.Add( new Point(60, 30));p.Points.Add( new Point(30, 60));Console.WriteLine(p.Points[1]);maingame.Children.Add(p); Console.WriteLine(p.Points[1]);Canvas.SetTop(p, 100.0);Console.WriteLine(p.Points[1]); |
|
This will output:
I want my collisionfunction to look like this: public static bool PolyCollision(Points[ ] p1, Points[ ] p2);
But this won't work becouse the points in the polygon never move.
I've figured out some sollutions that might work but i don't feel 100% comfortable with any of them.
1. Use Polygon as parameter instead of PointCollection and add the Canvas.Left / Top values to the collision-calculation.
- Not reusable in other frameworks.
2. Process all the points by adding the Canvas.Left etc -value before entering collisiondetection
- Performance?
3. Move all points individualy instead of using Canvas.Top / Left
- You can't inherit from Polygon. If you could it would be simple to add a built in property for this option, now i have to call another function to change to location of all the points.
How would you do? Maybe someone has another smart sollution 
If you are writing a game then using avalons layout system is very much barking up the wrong tree.
Since you will be explicitly managing the size and position of every element, the avalon layout system is simply overhead with no real benefit to you.
With the exception of game ui like intro and settings menus, I would recommend sticking to the Visual api.
Note Canvas and all our other existing controls and panels are visuals so all you have to do is add your game elements to a Canvas and muck around with their RenderTansform property to translate, scale and rotate the elements.
--Ifeanyi Echeruo[MSFT]