UWP XAML中的丢弃事件未触发(Windows 10)

时间:2015-10-26 08:46:05

标签: xaml windows-10 uwp

我正在开发一个适用于WIndows 10的应用程序,我想在两个列表中实现拖放功能。但在Windows 10应用程序中丢弃事件并未触发.. 以前它是Woring for Windows 8.1 .. 以下是我的代码:

<ListView Grid.Row="1" x:Name="TasksList" SelectionMode="None" HorizontalAlignment="Stretch" 
    ScrollViewer.VerticalScrollBarVisibility="Hidden" IsItemClickEnabled="True" 
    VerticalAlignment="Stretch" 
    ItemsSource="{Binding Tasks}"  ScrollViewer.VerticalScrollMode="Enabled" 
    CanReorderItems="True"  ShowsScrollingPlaceholders="False"
    DragItemsStarting="GridViewDragItemsStarting"  AllowDrop="True" IsSwipeEnabled="False"
    Drop="GridViewDrop" DragEnter="TasksList_DragEnter" CanDragItems="True"
    ItemContainerStyle="{StaticResource ClientListViewItemStyle}" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource MydesqBorderBrush}" Padding="10">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0" Width="80" Height="60" Background="{Binding DueDateIndicatorColor,Converter={StaticResource HexToSolidColorBrushConverter}}" VerticalAlignment="Top" HorizontalAlignment="Center">
                        <Image x:Name="ImgClient" Source="{Binding Client.ClientPictureUrl,Converter={StaticResource ServerUrlConverter}}" Stretch="Fill" Visibility="{Binding Source, Converter={StaticResource NullToInvisibilityConverter}, ElementName=ImgClient}" Width="80" Height="60"/>
                        <Image x:Name="ImgAccount" Source="{Binding ImageUrl}" Width="35" Height="35" Visibility="{Binding Source, Converter={StaticResource NullToInvisibilityConverter}, ElementName=ImgAccount}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Grid>
                    <Grid Grid.Column="1" Margin="10,0,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="{Binding TaskTitle}" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="20" Foreground="{Binding TitleColor, Converter={StaticResource HexToSolidColorBrushConverter}}"/>
                        <StackPanel Grid.Row="1" Orientation="Horizontal">
                            <Image  Width="20" Height="20" VerticalAlignment="Center" Source="/Assets/Images/user_gray.png" Margin="0,0,10,0"/>
                            <TextBlock Text="{Binding TaskType}" FontSize="16" VerticalAlignment="Center" Foreground="{Binding SubTitleColor, Converter={StaticResource HexToSolidColorBrushConverter}}" Margin="5,0,0,0"/>
                        </StackPanel>
                        <StackPanel Grid.Row="2" Orientation="Horizontal">
                            <Image Width="20" Height="20" VerticalAlignment="Center" Source="/Assets/Images/calendar_gray.png" Margin="0,0,10,0"/>
                            <TextBlock Text="{Binding DueDate, ConverterParameter=\{0:dd.MM.yyyy\}, Converter={StaticResource DateToStringConverter}}"  FontSize="16" VerticalAlignment="Center" Foreground="{Binding SubTitleColor, Converter={StaticResource HexToSolidColorBrushConverter}}" Margin="5,0,0,0"/>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="ItemClick">
            <behaviors:NavigateWithEventArgsToPageAction 
            TargetPage="Mydesq.Client.UWP.Views.AddTaskPage"
             EventArgsParameterPath="ClickedItem" />
        </Core:EventTriggerBehavior>
        <Core:EventTriggerBehavior EventName="Drop">
            <Core:InvokeCommandAction Command="{Binding DropTaskCommand}" CommandParameter="{Binding ElementName=TasksList,Path=SelectedItem}"/>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</ListView>

2 个答案:

答案 0 :(得分:4)

确保在ListView的DragEnter事件中设置AcceptedOperation属性。例如。像这样:

private void TasksList_DragEnter(object sender, DragEventArgs e)
{
   e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
}

答案 1 :(得分:0)

我在Grid

中与MainPage有类似的问题
 AllowDrop="True" 

修复了即使没有DragEnter事件。

(我知道你已经有了这个属性(我的答案是针对其他人的......)