检测列表框的滚动事件? [英] Detect Scrolling Event of ListBox?

查看:113
本文介绍了检测列表框的滚动事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有当一个列表框开始滚动事件开除了?

Is there an event fired when a ListBox begins to scroll?

目前,我有下面的代码,以允许无缝阻力,并从列表框中下降。

I currently have the following code to allow for a seamless drag and dropping from a 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>



然后在代码

And then in the code

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;
                }
            }
        }



我然后复制所选项目在列表框中,并直接将其放置在所选择的项目的当前位置。一切运作良好。

I then duplicate the selected item in the listbox, and place it directly over the current location of the selected item. All works well.

但是,如果用户开始滚动列表框,而不是draging在应用程序中的项目,重复的图像坐在ontop ListBox的,它看起来不专业。当用户拿起自己的手指,重复的项目被删除,因为我可以检测manipulationComplete事件,实现该项目是在错误的地方。

However, if the user begins to scroll the listBox instead of draging the item around the application, the duplicated image sits ontop of the listBox and it looks unprofessional. As soon as the user lifts their finger, the duplicated item is deleted, because I can detect the manipulationComplete event, and realize that the item is in the "wrong place".

有没有为我当滚动开始,而不是等待manipulationComplete事件?

Is there a way for me to delete the item when the scrolling begins instead of waiting for the manipulationComplete event?

<删除项目的方式A HREF =http://stackoverflow.com/questions/9190200/how-do-i-get-access-to-the-item-in-a-listbox-that-is-being-rendered-rather-than >相关问题的背景

推荐答案

没有,没有一个事件时触发的ListBox 卷轴,但是,您可以找到的ScrollViewer 这是的ListBox 模板内并处理< 。code>的ValueChanged 事件,一旦发生是由于开始滚动

No, there is not an event fired when the ListBox scrolls, however, you can locate the ScrollViewer which is within the ListBox template and handle the ValueChanged event which occurs as soon as scrolling starts.

您可以找到滚动条如下:

You can locate the scrollbar as follows:

/// <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();

}

这使用LINQ到Visual树,如<一个HREF =http://www.scottlogic.co.uk/blog/colin/2010/07/exposing-and-binding-to-a-silverlight-scrollviewer%E2%80%99s-scrollbars/相对=nofollow >这个博客帖子。

This uses Linq to Visual Tree, as described in this blog post.

这篇关于检测列表框的滚动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆