MouseDragElementBehavior in UWP



我目前正在将WPF/Silverlight中为Windows Phone 8制作的旧游戏移植到通用Windows平台。我已经制作了可以使用MouseDragElementBehavior类在画布中移动的字母。对于这个类,UWP 中是否有类似的内容?

有一个名为ManipulationDelta的事件,在评论中建议。以下是使用它的方法:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Canvas>
        <TextBlock
            FontSize="64"
            ManipulationDelta="LetterA_ManipulationDelta"
            ManipulationMode="All"
            RenderTransformOrigin="0.5,0.5"
            Text="A">
            <TextBlock.RenderTransform>
                <TranslateTransform x:Name="dragLetterA" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock
            FontSize="64"
            ManipulationDelta="LetterB_ManipulationDelta"
            ManipulationMode="All"
            RenderTransformOrigin="0.5,0.5"
            Text="B">
            <TextBlock.RenderTransform>
                <TranslateTransform x:Name="dragLetterB" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock
            FontSize="64"
            ManipulationDelta="LetterC_ManipulationDelta"
            ManipulationMode="All"
            RenderTransformOrigin="0.5,0.5"
            Text="C">
            <TextBlock.RenderTransform>
                <TranslateTransform x:Name="dragLetterC" />
            </TextBlock.RenderTransform>
        </TextBlock>
    </Canvas>
</Grid>

隐藏的代码如下所示:

private void LetterA_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    dragLetterA.X += e.Delta.Translation.X;
    dragLetterA.Y += e.Delta.Translation.Y;
}
private void LetterB_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    dragLetterB.X += e.Delta.Translation.X;
    dragLetterB.Y += e.Delta.Translation.Y;
}
private void LetterC_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    dragLetterC.X += e.Delta.Translation.X;
    dragLetterC.Y += e.Delta.Translation.Y;
}

就这么简单。

希望这有帮助。

最新更新