ListBox, Canvas 및 Thumb을 함께 사용하려면 어떻게합니까?ListBox, Canvas 및 Thumb을 함께 사용하려면 어떻게합니까?
나는 드래그 가능한 엄지 손가락을 포함하는 캔버스와 함께 ListBox의 선택 로직을 재사용하려고합니다.
Thumb이 마우스 이벤트를 처리하여 Thumb을 클릭해도 항목이 선택되지 않는 것처럼 보입니다.
절차형 코드의 대안을 사용하지 않고도 이러한 요소를 함께 사용할 수 있기를 기대했습니다. 이것이 가능한지 또는 어떻게해야하는지 아는 사람이라면 저에게 조언하십시오.
코드 예제가 이어집니다. XAML에서
나는이 목록 상자를 정의하고 ItemsPanel로 캔버스 지정, 내가 드래그 엄지 손가락을 만들로드 이벤트 핸들러에서
<Window x:Class="ListBoxCanvasThumb.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
Loaded="Window_Loaded"
>
<Grid>
<ListBox
x:Name="listBox"
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window>
을 ListBoxItem의에 포장, 캔버스에 높은 게재 순위를 설정하고 다음 목록 상자에 추가 :
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Thumb t = new Thumb();
t.Width = 10;
t.Height = 10;
t.DragDelta += new DragDeltaEventHandler(thumb_DragDelta);
ListBoxItem i = new ListBoxItem();
Canvas.SetLeft(i, 10);
Canvas.SetTop(i, 10);
i.Content = t;
listBox.Items.Add(i);
}
을 DragDelta 이벤트 처리기에서 나는 캔버스에 항목의 위치 업데이트 :
void thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
ListBoxItem i = (ListBoxItem)((Thumb)sender).Parent;
Canvas.SetLeft(i, Canvas.GetLeft(i) + e.HorizontalChange);
Canvas.SetTop(i, Canvas.GetTop(i) + e.VerticalChange);
}
을
이것은 나를 위해 작동하지 않습니다. 여전히 클릭을 삼켜 서 목록 상자가 선택되지 않습니다. 당신이 @AshleyDavis 그것을 고칠 수 있었습니까? – Carlo