当列表框开始滚动时是否会触发事件?
我目前有以下代码,可以从列表框中无缝拖放。
<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>
然后在代码中
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;
}
}
}
然后,我在列表框中复制所选项目,并将其直接放置在所选项目的当前位置上方。一切运作良好。
但是,如果用户开始滚动列表框而不是在应用程序周围拖动项目,则重复的图像将位于列表框的顶部,看起来不专业。一旦用户抬起手指,重复的项目就会被删除,因为我可以检测到操作完成事件,并意识到该项目位于“错误的位置”。
有没有办法让我在滚动开始时删除该项目,而不是等待操作完成事件?
Related问题context:
不,当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();
}
这使用 Linq to Visual Tree,如中所述这篇博文.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)