首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wpf列表视图滚动在拖放情况下无法正常工作

Wpf列表视图滚动在拖放情况下无法正常工作
EN

Stack Overflow用户
提问于 2016-01-19 17:34:59
回答 1查看 447关注 0票数 1

我有以下Xaml代码

代码语言:javascript
复制
    <ListView x:Name="ListView" ItemsSource="{Binding Values}" MaxHeight="400" MaxWidth="500" MinWidth="160"
              VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"  ScrollViewer.IsDeferredScrollingEnabled="True"
              MouseMove="ListView_MouseMove">
        <ListView.View>
            <GridView x:Name="GridView" ColumnHeaderContainerStyle="{StaticResource HeaderStyle}">
                <!--<GridViewColumn Header="ID" DisplayMemberBinding="{Binding [0]}"  CellTemplate="{StaticResource ColumnCellTemplate}" />
                <GridViewColumn Header="Test" DisplayMemberBinding="{Binding [1]}" CellTemplate="{StaticResource ColumnCellTemplate}"/>-->
            </GridView>
        </ListView.View>
    </ListView>

以及我的问题的相关代码,如下所示

代码语言:javascript
复制
 Private Sub ListView_MouseMove(sender As Object, e As MouseEventArgs)
        MyBase.OnMouseMove(e)
        Dim viewModel As QuestionAnswerViewModel = CType(DataContext, QuestionAnswerViewModel)
       'Dim vis As Visual = e.OriginalSource()
        If e.LeftButton = MouseButtonState.Pressed And viewModel IsNot Nothing AndAlso viewModel.Value IsNot Nothing Then
            Dim data As New DataObject
            data.SetData(DataFormats.StringFormat, viewModel.Value)

            'Inititate the drag-and-drop operation.
            DragDrop.DoDragDrop(Me, data, DragDropEffects.Copy Or DragDropEffects.Move)
        End If
    End Sub

现在我的代码的问题是,当我滚动时,MouseMove事件会被触发,当然,拖放方法也会触发。我想问一下如何正确使用e.OriginalSource()方法来查看用户是否正在拖动滚动条。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-01-19 18:10:41

为了使滚动正常工作,我刚刚在If语句Not e.OriginalSource().GetType().Equals(GetType(Thumb))中添加了一个新检查

完整的代码现在如下所示

代码语言:javascript
复制
  Private Sub ListView_MouseMove(sender As Object, e As MouseEventArgs)
        MyBase.OnMouseMove(e)
        Dim viewModel As QuestionAnswerViewModel = CType(DataContext, QuestionAnswerViewModel)

        If e.LeftButton = MouseButtonState.Pressed And viewModel IsNot Nothing AndAlso viewModel.Value IsNot Nothing _
                AndAlso Not e.OriginalSource().GetType().Equals(GetType(Thumb)) Then
            Dim data As New DataObject
            data.SetData(DataFormats.StringFormat, viewModel.Value)

            DragDrop.DoDragDrop(Me, data, DragDropEffects.Copy Or DragDropEffects.Move)
        End If
    End Sub

现在,每当我拖动滚动条时,代码都不会进入If语句中,因此滚动条将正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34873127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档