0

I have a 50x50 draggable grid inside another grid that I am able to move around with the cursor. (I forgot that I am using the DraggableExtender class

The problem is that I want the moveable grid to be relatively positioned inside it's container grid no matter how the container grid is resized. My solution right now is to dynamically change the HorizontalAlignment and VerticalAlignment of the moveable grid whenever it is moved, but this is hacky and doesn't work well.

Relative positioning in a grid is one of the easiest things to do in XAML, but not when you have draggable elements ;(

Any ideas?

EDIT for code and images:

My XAML:

<Grid Margin="10" ClipToBounds="True" Background="#FFB4B4B4">
  <Grid Name="testGrid" MouseLeftButtonDown="testGrid_MouseLeftButtonDown" MouseLeftButtonUp="testGrid_MouseLeftButtonUp" RenderTransformOrigin="0.5,0.5" Height="100" Margin="50,0,0,0" Width="100" Background="#FFE6E6E6" local:DraggableExtenderGrid.CanDrag="true" HorizontalAlignment="Center"/>
</Grid>

and I use a DraggableExtender class (shown here) which I have edited to apply to a Grid instead of a Canvas (I was hoping for better results from a grid.. but both containers produce the same result, even with the original class on a canvas).

This is a picture of my 2 grids. I can move the smaller grid around inside it's parent grid, but I would like for it to maintain relative positioning once the window is resized. This is what it currently looks like when I resize the window. In this particular example, the grid would ideally remain slightly off-center horizontally and vertically in both pictures.

Community
  • 1
  • 1

1 Answers1

0

May be you should try placing the Grid inside a Canvas instead..

Take a look here

Community
  • 1
  • 1
bit
  • 4,407
  • 1
  • 28
  • 50
  • Thanks for the suggestion. Unfortunately, it's what I tried first ;( I figured the grid would provide me better relative positioning, but it isn't working out so far – Jacob Anderson Aug 13 '14 at 05:18