目前,我有ListBox
用于执行拖放操作。虽然这确实有效但是如果选择了列表中的项目,则用户无法使用垂直滚动条并单击其上的光标。用户只能使用鼠标滚轮移动此滚动条。
根据我的理解,我认为它会尝试将滚动条计为SelectedItem
,这可能是为什么它无法正常移动,但我仍然不确定为什么会发生这种情况。下面是相关代码,非常感谢任何有关解决此问题的帮助。
<ListBox x:Name="WriteListBox"
Height="326"
Width="190"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="428,25,0,0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown"
PreviewMouseMove="ListBox_PreviewMouseMove"
ItemTemplate="{StaticResource ModelVariableWriteTemplate}" />
private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.mousePoint = e.GetPosition(null);
}
private void ListBox_PreviewMouseMove(object sender, MouseEventArgs e)
{
Point newPoint = e.GetPosition(null);
Vector diff = this.mousePoint - newPoint;
ListBox listBox = sender as ListBox;
var listBoxItem = listBox.SelectedItem;
if (e.LeftButton == MouseButtonState.Pressed)
{
///Drag/Drop stuff here.
}
}
答案 0 :(得分:3)
ScrollViewer是ListBox的一部分,ListBox是ListBox_PreviewMouseMove的发送对象。我认为使ListBoxItem成为发送者,而不是ListBox,应该从该事件中删除ScrollViewer。