C#拖放,为什么图像翻转?

时间:2013-08-04 15:50:18

标签: c# xaml drag-and-drop

我正在使用C#和XAML开发Metro应用程序,页面具有拖放功能。

出于某种原因,当图像在该区域中掉落时,它会在图像中掉落而翻转过来。

继承了XAML代码

<ScrollViewer Height="247"
        Grid.Row="1"
        HorizontalScrollMode ="Enabled"
        HorizontalScrollBarVisibility ="Visible"
        VerticalScrollMode ="Disabled"
        VerticalScrollBarVisibility ="Disabled" Margin="10,0,449,442" >

        <GridView x:Name="availableItems" 
            CanDragItems="True"
            CanReorderItems="True"
            DragItemsStarting="dragItem"
                  AllowDrop="True"
            Drop="dropItemSource"
            Width="auto"
            ItemsSource="{Binding source}" >
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Image Source="{Binding Image}" Width="163" Height="247" />
                </DataTemplate>
            </GridView.ItemTemplate>

        </GridView>
    </ScrollViewer>
    <Grid Grid.Row="1">
    <GridView x:Name="chosenItems"
              CanDragItems="True"
              CanReorderItems="True"
              AllowDrop="True"
              DragItemsStarting="dragItem"
              Drop="dropItemDestination"
              ItemsSource="{Binding destination}" Margin="135,405,144,93" RenderTransformOrigin="0.5,0.5" Grid.Row="1" Background="#FFD18F8F">

        <GridView.RenderTransform>
            <CompositeTransform ScaleY="-1"/>
        </GridView.RenderTransform>
        <GridView.ItemTemplate>
            <DataTemplate>
                <Image Source="{Binding Image}" Width="163" Height="247" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            </DataTemplate>
        </GridView.ItemTemplate>

    </GridView>

并且继承了C#代码

protected override void OnNavigatedTo(NavigationEventArgs e)
    {


        source.Add(new Item("Assets/Achord.png"));
        source.Add(new Item("Assets/Bchord.png"));
        source.Add(new Item("Assets/Cchord.png"));
        source.Add(new Item("Assets/Dchord.png"));
        source.Add(new Item("Assets/Echord.png"));
        source.Add(new Item("Assets/Fchord.png"));
        source.Add(new Item("Assets/Gchord.png"));

        availableItems.ItemsSource = source;
        chosenItems.ItemsSource = destination;

    }

    private void dragItem(object sender, DragItemsStartingEventArgs e)
    {
        draggedItem =(Item) e.Items[0];
    }

    private void dropItemDestination(object sender, DragEventArgs e)
    {
        source.Remove(draggedItem);
        destination.Insert(0, draggedItem);
    }
    private void dropItemSource(object sender, DragEventArgs e)
    {
        destination.Remove(draggedItem);
        source.Add(draggedItem);
    }
}
public class Item
{
    public  Item(string image)
    {
        this.Image = image;
    }
    public string Image
    {
        get;
        set;
    }
}

这是一个特殊的问题,我已经尝试将断点放入,看看代码是否在对图像做某些事情,但我看不到任何东西。

1 个答案:

答案 0 :(得分:0)

这似乎是因为您的比例因子是负数。

<GridView.RenderTransform>
   <CompositeTransform ScaleY="-1"/>
</GridView.RenderTransform>