1

我在 C# 和 XAML 中开发 Metro App,页面具有拖放功能。

由于某种原因,当图像被丢弃在该区域时,它被丢弃在图像中翻转倒置。

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

这是一个特殊的问题,我尝试在其中设置断点以查看代码是否在任何时候对图像进行了某些操作,但我什么也看不到。

4

1 回答 1

0

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

<GridView.RenderTransform>
   <CompositeTransform ScaleY="-1"/>
</GridView.RenderTransform>
于 2013-08-04T15:59:48.447 回答