简体   繁体   English

C#通用应用程序:拖动时的图像前景

[英]C# Universal App: Image foreground while dragging

I have this puzzle game where I can movie pieces on the playfield. 我有一个益智游戏,可以在运动场上拍摄电影。

I recently added a touchscreen way to do that, it works, but there is an issue. 我最近添加了一种触摸屏方法来执行此操作,它可以工作,但是存在问题。 When I move an image from one place to another, the dragged image is in the background, the other images are in the foreground, I would like to have it the other way, see Screenshot. 当我将图像从一个位置移动到另一个位置时,所拖动的图像在背景中,其他图像在前景中,我想换一种方式,请参见截屏。 1 1

My delta function is this: 我的增量功能是这样的:

   public void Touch_Delta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
    {
        Image img_touched = (Image)sender;


        TranslateTransform _Transform = (img_touched.RenderTransform = (img_touched.RenderTransform as TranslateTransform) ?? new TranslateTransform()) as TranslateTransform;
        _Transform.X += e.Delta.Translation.X;
        _Transform.Y += e.Delta.Translation.Y;

        if(_Transform.X > 90.0)
        {
            img_touched.RenderTransform = null;
            Move_Right(this, null);
        }
        else if(_Transform.X < -90)
        {
            img_touched.RenderTransform = null;
            Move_Left(this, null);
        }
        else if (_Transform.Y > 90.0)
        {
            img_touched.RenderTransform = null;
            Move_Down(this, null);
        }
        else if (_Transform.Y < -90.0)
        {
            img_touched.RenderTransform = null;
            Move_Up(this, null);
        }

        Rotate_Touch += e.Delta.Rotation;
        if(Rotate_Touch > 55.0)
        {
            Rotate_Right(this, null);
            Rotate_Touch = 0;
        }
        else if(Rotate_Touch < -55.0)
        {
            Rotate_Left(this, null);
            Rotate_Touch = 0;
        }

    }

The corresponding XAML is this: 相应的XAML是这样的:

<UserControl
    x:Class="PictureSplitter.Views.PictureView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="768"
    d:DesignWidth="1024">

    <Grid Height="1000" Width="600" Background="Black">
    <GridView ItemsSource="{Binding Splitter.PuzzlePositions}" Background="Black">
        <GridView.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="#FF888E91" BorderThickness="2" Background="Black">
                    <Grid Name="picGrid" Background="Black" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>

                            <Image Source="{Binding Piece.ImageSource}" Tapped="Image_Tapped" ManipulationMode="All" CanDrag="False" Loaded="Load_Events" />
                    </Grid>
                </Border>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
    </Grid>
</UserControl>

I know there is a zindex in the Windows.Canvas thing, but I haven't found something similar here. 我知道Windows.Canvas中有一个zindex,但是我在这里没有找到类似的东西。 Is there a way to do this? 有没有办法做到这一点?

触摸拖动

Well normally if there is no z-index the elements will follow the z order they were written/generated - I guess if you try to move the 3rd element onto the 2nd one it'd be on top of it :) 正常情况下,如果没有z-index,则元素将遵循它们被写入/生成的z顺序-我猜如果您尝试将第3个元素移到第2个元素上,它就会放在它上面:)

Now without using canvas I don't think you can do this, because even the new Transform3D stuff respects the original Z order, so if you'd move one item "above" the others (translate-z: +1) it would still be drawn behind the next ones. 现在,不使用画布,我不认为您可以执行此操作,因为即使新的Transform3D素材也遵循原始的Z顺序,因此,如果将一个项目“移至”其他项目“之上”(translate-z:+1),它将仍然被吸引到下一个。

With all this: use a canvas - It's better for a game anyway ;) 所有这些:使用画布-无论如何,这对于游戏来说更好;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM