0

我正在开发一个 UWP 应用程序,我在其中实现了一个带有一些数据模板的列表视图:

<Page
x:Class="ListView_DragDrop.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ListView_DragDrop"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
    <DataTemplate x:Name="StyleTile1">
        <Grid Height="100" Width="100" Background="Green" AllowDrop="True" CanDrag="True" DragStarting="Grid_DragStarting" Drop="Grid_Drop">
            <TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center" Drop="Grid_Drop"/>
        </Grid>
    </DataTemplate>
    <DataTemplate x:Name="StyleTile2">
        <Grid Height="200" Width="200" Background="Purple" AllowDrop="True" CanDrag="True" DragStarting="Grid_DragStarting" Drop="Grid_Drop">
            <TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center" Drop="Grid_Drop"/>
        </Grid>
    </DataTemplate>
    <DataTemplate x:Name="StyleTile3">
        <Grid Height="50" Width="50" Background="Red" AllowDrop="True" CanDrag="True" DragStarting="Grid_DragStarting" Drop="Grid_Drop">
            <TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center" Drop="Grid_Drop"/>
        </Grid>
    </DataTemplate>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ListView x:Name="myListView" ReorderMode="Enabled" CanDrag="True" CanDragItems="True" CanReorderItems="True" AllowDrop="True" Drop="Grid_Drop">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <ItemsWrapGrid Orientation="Horizontal" Drop="Grid_Drop"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.Items>
            <ListBoxItem Content="Tile1" ContentTemplate="{StaticResource StyleTile1}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile2" ContentTemplate="{StaticResource StyleTile1}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile3" ContentTemplate="{StaticResource StyleTile3}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile4" ContentTemplate="{StaticResource StyleTile2}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile5" ContentTemplate="{StaticResource StyleTile3}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile6" ContentTemplate="{StaticResource StyleTile3}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile7" ContentTemplate="{StaticResource StyleTile2}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile8" ContentTemplate="{StaticResource StyleTile1}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile9" ContentTemplate="{StaticResource StyleTile2}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
            <ListBoxItem Content="Tile10" ContentTemplate="{StaticResource StyleTile1}" CanDrag="True" AllowDrop="True" Height="Auto" Width="Auto" Drop="Grid_Drop"/>
        </ListView.Items>
    </ListView>
</Grid>

我想在其中执行拖放操作。你能告诉我如何达到同样的效果吗?

4

0 回答 0