views:

41

answers:

2

Hello There,

I'm writing an application which is basically a designer very similar like Expression Blend or Visual Studio designer. So basically there are a bunch of UI elements on a design surface and you can do things such as drag'n'drop, resize, rotate, etc.

The main container control, which will be the designsurface can be any control which is derived from Panel which includes controls such as Canvas, Grid, etc. This situtaion, meaning the support of any Panel derived control as designsurface, raises a problem where I need to find a common way to set size and lcoation of child controls on that surface no matter the ptype of arent panel control is.

I use UIElement.Arrange() call to move/resize the controls around and this works but once the layout of the parent panel control is updated, such as when you resize it, all my changes get reset to their default. I'm also aware the current 2 pass layout logic in WPF panel controls but there is no way for me to derive from a control and use as a background object.

So in short, is there a general way to achieve what I want, setting size/position of a child control in a panel derived control,as I see Blend/VS Designer does recognize how to position controls in a panel derived control? Or are they hardcoded for known Panel derived controls as well?

Thanks in advance...

Özden

A: 

Have you tried changing the margin on your child control, that will let you change it's position. I don't think that it is the optimal way of doing it, but it would work.

viggity
Thanks for the response...For Grid control, Margin is used as you said. But, for example, when you use Canvas in Blend, it sets Canvas.Left property instead. I just want to understand whether a common way is available to understand the capability of the parent and set the right property for positioning.So far, all my research leads to a point that this is not possible, maybe blend/VS does hardcode this as well. Maybe I should use TranslateTransform instead, which is the only thing I found in common across all possible scenarios.
Özden Irmak
A: 

You can't do it, the whole point of the different panel types id that they position their children differently.

Canvas is designed for manually controlling size and position, on Grid you can set the margin - but there is no way to control the position on StackPanel, WrapPanel or DockPanel (or the radial panel you can find in almost any WPF sample collection)

Nir