UWP 向 Grid 多个单元格添加拖放操作

我想用 UWP(通用 Windows 平台)构建一个应用程序。使用应用程序,我想实现“拖放”功能。我使用了一些名为“AllowDrop”和“DragOver”的属性。但是我遇到了网格或一些 xaml 层次结构的问题。

当我将任何文件拖放到应用程序的任何位置时,我希望应用程序接受它。但有一个未知问题,应用程序只接受文件的特定区域。我希望以下图片可以帮助您了解我遇到的问题。 我的意图(左)但它有效(右)

http://img4.mukewang.com/61a36f610001a47b11460640.jpg

下面是源代码(一个是xaml源,一个是csharp)。


<Page 

    x:Class="eeee_textRandomizeUWP.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:eeee_textRandomizeUWP"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">


    <Grid AllowDrop="True" DragOver="Grid_DragOver">

        <Grid.RowDefinitions>

            <RowDefinition Height="6*"/>

            <RowDefinition Height="*"/>

        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="3*"/>

            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>

        <StackPanel>


            <TextBlock Text="파일을 올려주세요" FontSize="{ThemeResource ListViewHeaderItemThemeFontSize}" Margin="20, 0, 0, 0"/>

            <ListView Name="MainFileList">

                <ListViewItem>

                    <StackPanel Orientation="Horizontal">

                       <TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" /> 

                    </StackPanel>

                </ListViewItem>

            </ListView>


        </StackPanel> 

    </Grid>


</Page>

我认为我对 Csharp 部分没有问题,但对 xaml 部分没有问题。我想知道它只适用于一个网格单元,即使我从字面上向“主网格”添加拖动动作。我说过拖放仅适用于网格的一个单元格。但是当我考虑单元格的高度时,有效区域太小了。

当我发现这个问题时,我将我的动作移到了“页面”标签。但它的工作原理与“网格”标签中的动作相同。我不知道我的问题是什么。


狐的传说
浏览 219回答 2
2回答

慕娘9325324

它在 Grid 标签中不起作用,因为您有另一个框覆盖它,因此您将任何东西拖到另一层之上,而不是网格本身。

萧十郎

我最终得到了这个来源。只需在网格标签的末尾添加画布标签。我仍然想知道我为什么要这样做。但它有效。不要减去 Canvas 的背景设置。<Page&nbsp;&nbsp; &nbsp; x:Class="eeee_textRandomizeUWP.MainPage"&nbsp; &nbsp; xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&nbsp; &nbsp; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&nbsp; &nbsp; xmlns:local="using:eeee_textRandomizeUWP"&nbsp; &nbsp; xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&nbsp; &nbsp; xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&nbsp; &nbsp; mc:Ignorable="d"&nbsp; &nbsp; Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">&nbsp; &nbsp; <Grid >&nbsp; &nbsp; &nbsp; &nbsp; <Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="6*"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="*"/>&nbsp; &nbsp; &nbsp; &nbsp; </Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; <Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="3*"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="*"/>&nbsp; &nbsp; &nbsp; &nbsp; </Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; <StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="파일을 올려주세요" FontSize="{ThemeResource ListViewHeaderItemThemeFontSize}" Margin="20, 0, 0, 0"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListView Name="MainFileList">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListView>&nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; <ListView Grid.Column="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<TextBlock Text="&#xE8E5;" FontFamily="Segoe MDL2 Assets" />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ListViewItem>&nbsp; &nbsp; &nbsp; &nbsp; </ListView>&nbsp; &nbsp; &nbsp; &nbsp; <Canvas&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Background="Transparent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Grid.RowSpan="2"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Grid.ColumnSpan="2"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AllowDrop="True"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DragOver="Grid_DragOver"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; </Canvas>&nbsp; &nbsp; </Grid></Page>
打开App,查看更多内容
随时随地看视频慕课网APP