How to stop Grid Child Elements from resizing on Grid.RenderTransform

96 views Asked by At

Okay, so I have a Grid with 4 child Images, each positioned in all four corners of the Grid like so. Grid with Children

The purpose of the bottom two Child Images, is to stretch the grid. So when the user drags these corners, the Grid will stretch.

My problem is that the Children will stretch too, which I don't want.

Stretched Grid

Is there any way to ensure that the size of the children does not stretch with the Grid?

Thanks.

P.S. I could detach the Child Images from the Grid, but it is much simpler and more elegant this way as the x/y positions remain at the edges of the Grid perfectly, I just want to ensure they do not Scale with it, if possible.

Create Grid and add Children

//ImageGrid
ImageControl.Height = 500;
ImageControl.Width = 500;
ImageControl.ManipulationMode = ManipulationModes.All;

canvas.Children.Add(ImageControl);

ImageControl.Children.Add(tickBtn);
ImageControl.Children.Add(delBtn);
ImageControl.Children.Add(skewBtn);
ImageControl.Children.Add(strBtn);

ImageManipulation.Image_Drag = new CompositeTransform();
ImageManipulation.Image_Drag.CenterX = imW / 2;
ImageManipulation.Image_Drag.CenterY = imH / 2;

ImageControl.RenderTransform = ImageManipulation.Image_Drag;
strBtn.ManipulationDelta += ImageManipulation.resBtn_Manip;
skewBtn.ManipulationDelta += MaskManipulation.skewBtn_Manip;
dragControl.ManipulationDelta += ImageManipulation.movBtn_Manip;

Manipulation Class

public static CompositeTransform Image_Drag;

public static void resBtn_Manip(object sender, ManipulationDeltaRoutedEventArgs e) 
{

    Mask_Drag.ScaleX += e.Delta.Translation.X;
    Mask_Drag.ScaleY += e.Delta.Translation.X;
}

public static void movBtn_Manip(object sender, ManipulationDeltaRoutedEventArgs e) 
{
    Mask_Drag.TranslateX += e.Delta.Translation.X;
    Mask_Drag.TranslateY += e.Delta.Translation.Y;
}

public static void skewBtn_Manip(object sender, ManipulationDeltaRoutedEventArgs e) 
{

    Mask_Drag.ScaleX -= e.Delta.Translation.X;
    Mask_Drag.ScaleY += e.Delta.Translation.Y;

    if (Mask_Drag.ScaleX < 0.5)

    {
        Mask_Drag.ScaleX = 0.5;
    }

    if (Mask_Drag.ScaleY < 0.5) 

    {
        Mask_Drag.ScaleY = 0.5;
    }
}
0

There are 0 answers