1

我试图通过使用事件 ManiuplationDelta 的 e.CumulativeManipulation.Translation.X 围绕 Y 轴旋转一些 stackPanel,然后当 stackPanel.Projection.rotationY 接近 90 度时,旋转变得很奇怪。调试后我发现 e.CumulativeManipulation.Translation.X 值有时是 -2000 或 3000 等。

为什么它报告这么大(错误)的数字。有什么帮助吗?

检查下面的代码片段。

Xaml

<Grid x:Name="ContentPanel" Background="Yellow" Grid.Row="1" Margin="12,0,12,0" >
<StackPanel x:Name="Under" Background="DarkCyan" ManipulationDelta="ContentPanel_ManipulationDelta" >
            <TextBlock Text="Under" Foreground="Blue" FontSize="48"/>
            <StackPanel.Projection>
                <PlaneProjection CenterOfRotationX="0.5" CenterOfRotationY="0.5" RotationY="0"/>
            </StackPanel.Projection>

    </Grid>

C#

  private void ContentPanel_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
    {
        ;
        double FullWidth = (sender as FrameworkElement).ActualWidth;
        delta = e.CumulativeManipulation.Translation.X;
        if (Math.Abs(delta) > FullWidth)
        {
            //Something wrong
            Debug.WriteLine("Cumulative x: " + e.CumulativeManipulation.Translation.X);
            Debug.WriteLine("width: " + (sender as FrameworkElement).ActualWidth);
            Debug.WriteLine("");
        }
        double RotateValue = (delta / FullWidth) * -180;
        var Underprojection = (Under.Projection as PlaneProjection);
        Underprojection.RotationY = RotateValue;
    }

编辑:我发现了问题,我没有将 CenterOfRotationZ 设置为值“0.5”

4

0 回答 0