0
아직 시도하고 있습니다. 아무 단서도. 나는 ListBox를 드래그하여 & Drop 항목을 이동하고 새 항목을 추가합니다. 내가 뭘 하려는지 사용자가 아무것도 마우스 왼쪽 버튼으로 항목을 클릭하면됩니다. 마우스 오른쪽 버튼으로 클릭하면 선택됩니다 (다중 선택). e.Handled = true
을 시도했지만 문제는 마우스로 스크롤 할 수 없다는 것입니다. 내 목록 상자의 이벤트 :ListBox에서 마우스 오른쪽 버튼을 클릭 한 상태에서만 선택 항목 허용
private void LB_SongList_Drop(object sender, DragEventArgs e)
{
ListBox parent = sender as ListBox;
Song data = e.Data.GetData(typeof(Song)) as Song;
Song objectToPlaceBefore = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song;
if (data != null && objectToPlaceBefore != null)
{
[...]//Code that moves object
parent.SelectedItems.Remove(data);
}
else
{
String[] file = e.Data.GetData(DataFormats.FileDrop, true) as String[];
if (file != null)
{
[...]//Code that adds new data
}
}
}
private void LB_SongList_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (!b_IsScrolling)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
MainPointer.Main_AllowClose = false;
ListBox parent = sender as ListBox;
Song data = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song;
if (data != null)
{
parent.SelectedItems.Remove(data);
DragDrop.DoDragDrop(parent, data, DragDropEffects.Move);
}
}
}
}
private static object GetObjectDataFromPoint(ListBox source, Point point)
{
UIElement element = source.InputHitTest(point) as UIElement;
if (element != null)
{
object data = DependencyProperty.UnsetValue;
while (data == DependencyProperty.UnsetValue)
{
data = source.ItemContainerGenerator.ItemFromContainer(element);
if (data == DependencyProperty.UnsetValue) element = VisualTreeHelper.GetParent(element) as UIElement;
if (element == source) return null;
}
if (data != DependencyProperty.UnsetValue) return data;
}
return null;
}
private void LB_SongList_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
ListBox parent = sender as ListBox;
Song data = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song;
if (data != null)
{
LB_SongList.SelectedItems.Remove(data);
[...]//Code that plays a song on double click (should allow only left mouse button)
}
}
}
private void LB_SongList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LB_SongList.SelectedItems.Count != 0)
{
[...]
}
else
{
[...]
}
}
사람이 도움을 수 있을까? 왼쪽 마우스 단추로 항목을 선택하지 않습니다. 마우스 오른쪽 버튼은 항목을 선택합니다 (다중).
xaml을 (를) 게시하십시오. –