1

我很难理解为什么画布和网格都不能使用 RenderTransform 调整大小,如果它们放置在滚动查看器中?如果从滚动查看器中取出,网格或画布会调整大小,但显然它不再是可滚动的。

XAML 代码

<Grid x:Name="ContentPanel">
    <ScrollViewer VerticalScrollBarVisibility="Auto"
                  HorizontalScrollBarVisibility="Auto"
                  Margin="0,0,0,0"
                  x:Name="scrollWindow">
        <Grid HorizontalAlignment="Left"
                x:Name="primaryGrid"
                VerticalAlignment="Top">
        </Grid>
    </ScrollViewer>
</Grid>

C# 代码

public class MyClass
{
    private TranslateTransform move = new TranslateTransform();
    private ScaleTransform resize = new ScaleTransform();
    private TransformGroup transform= new TransformGroup();

    public MyClass(Grid primaryGrid, ScrollViewer scrollWindow)
    {
        transform.Children.Add(move);
        transform.Children.Add(resize);

        scrollWindow.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(testManipulationDelta);
        scrollWindow.ManipulationMode = ManipulationMode.System;

        primaryGrid.RenderTransform = transform;
    }

    void testManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        if (e.DeltaManipulation.Scale.X > 0 && e.DeltaManipulation.Scale.Y > 0)
        {
            resize.ScaleX *= e.DeltaManipulation.Scale.X;
            resize.ScaleY *= e.DeltaManipulation.Scale.X;
        }
    }
}

有人可以启发我吗?

4

0 回答 0