检测列表框的滚动事件?

Bob*_*Bob 5 c# listbox windows-phone-7

当 ListBox 开始滚动时是否会触发事件?

我目前有以下代码来允许从列表框中无缝拖放。

<ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" Margin="-5"  />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate >
                    <DataTemplate>

                        <Image  ManipulationStarted="ListImage_ManipulationStarted" Tag="{Binding selfReference}"   x:Name="ListImage" Margin="2.5" Stretch="Fill" Source="{Binding thumbnailURL}" Height="64" Width="64"/>

                    </DataTemplate>
                </ListBox.ItemTemplate>

            </ListBox>
Run Code Online (Sandbox Code Playgroud)

然后在代码中

private void ListImage_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            if (dImage == null)
            {
                SoundEffectModel selectedModel = (sender as Image).Tag as SoundEffectModel;
                int newIndex = listBoxSource.Items.IndexOf(selectedModel);
                if (newIndex != -1)
                {
                    listBoxSource.SelectedIndex = newIndex;
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

然后我复制列表框中的所选项目,并将其直接放置在所选项目的当前位置上。一切正常。

但是,如果用户开始滚动列表框而不是在应用程序周围拖动项目,则复制的图像位于列表框的顶部并且看起来不专业。只要用户抬起手指,重复的项目就会被删除,因为我可以检测到操作完成事件,并意识到该项目位于“错误的地方”。

有没有办法在滚动开始时删除项目而不是等待操作完成事件?


上下文的相关问题:

Col*_*inE 2

不,滚动时不会触发事件ListBox,但是,您可以在模板ScrollViewer内找到该事件ListBox并处理ValueChanged滚动开始时发生的事件。

您可以按如下方式找到滚动条:

/// <summary>
/// Searches the descendants of the given element, looking for a scrollbar
/// with the given orientation.
/// </summary>
private static ScrollBar GetScrollBar(FrameworkElement fe, Orientation orientation)
{
  return fe.Descendants()
            .OfType<ScrollBar>()
            .Where(s => s.Orientation == orientation)
            .SingleOrDefault();

}
Run Code Online (Sandbox Code Playgroud)

这使用了 Linq to Visual Tree,如本博客文章中所述。