4
ListBox开始滚动时是否触发事件?检测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>
然后在代码
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;
}
}
}
我然后复制在列表框中选择的项目,并直接将其在选定项目的当前位置。一切运作良好。
但是,如果用户开始滚动listBox而不是拖动应用程序周围的项目,重复的图像位于listBox的顶部,它看起来不专业。只要用户抬起手指,重复的项目就会被删除,因为我可以检测到manipulateComplete事件,并意识到该项目位于“错误的地方”。
当滚动开始而不是等待manipulateComplete事件时,有没有办法让我删除该项目?
Thanks @ColinE为了让答案更完整,我会这样做:ScrollBar lbScrollBar = GetScrollBar(listbox,orientation).ValueChanged + = eventHandler;?还是还有其他一些步骤我需要做? – Bob 2012-02-12 16:04:33
@Bob是的,抱歉忘了补充一点。使用上述方法找到ScrollBar,然后处理ValueCganged。确保ListBox Loaded事件先被触发。 – ColinE 2012-02-12 16:07:43
这种解决方案可能不适用于Windows Phone吗?我在fe.Descendants上遇到错误? – Bob 2012-02-12 16:13:29