C#Universal App:拖动时的图像前景

时间:2015-12-12 18:08:03

标签: c# windows xaml touch uwp

我有这个益智游戏,我可以在游戏场上拍摄电影。

我最近添加了一个触摸屏方式,它可以工作,但有一个问题。 当我将图像从一个地方移动到另一个地方时,拖动的图像在背景中,其他图像在前景中,我想以另一种方式使用它,请参见屏幕截图。 insertion sort

我的delta函数是:

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

    }

相应的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>

我知道Windows.Canvas中有一个zindex,但我在这里找不到类似的东西。有没有办法做到这一点?

1

1 个答案:

答案 0 :(得分:0)

通常情况下,如果没有z-index,元素将遵循它们被编写/生成的z顺序 - 我想如果你试图将第3个元素移动到第2个元素上,它就会在它上面: )

现在不使用画布我不认为你可以做到这一点,因为即使是新的Transform3D东西都尊重原始的Z顺序,所以如果你移动一个项目&#34;以上&#34;其他人(translate-z:+1)它仍将被引入下一个。

所有这些:使用画布 - 无论如何它对游戏来说更好;)