0

好的,所以我有一个Grid带有 4 个孩子的孩子Images,每个孩子都位于所有四个角落,Grid就像这样。 带孩子的网格

底部两个 Child 的目的Images是拉伸网格。所以当用户拖动这些角时,Grid就会拉伸。

我的问题是孩子们也会伸展,这是我不想要的。

拉伸网格

有没有什么办法可以保证孩子的大小不跟的Grid

谢谢。

PS我可以将 ChildImages从 中分离出来Grid,但是这种方式更简单,更优雅,因为 x/y 位置保持在Grid完美的边缘,我只想确保它们不会Scale使用它,如果可能的话。

创建网格并添加子项

//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;

操作类

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;
    }
}
4

0 回答 0