我使用ItemsControl
来表示Canvas
中贝塞尔曲线的控制点。我需要能够在MouseDown
上捕获Ellipse
事件以在移动期间检索光标位置,这样我就可以实时更新贝塞尔曲线。
MouseDown
也PreviewMouseDown
有效。我已经google了很多并且进行了大量的实验,但我猜我在问错误的问题。
<ItemsControl Name="DirectivePointsControl"
Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding VisibleDirectivePoints}"
Width="{Binding ElementName=MainMapImage, Path=ActualWidth}"
Height="{Binding ElementName=MainMapImage, Path=ActualHeight}"
Focusable="False"
>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<jas:DragCanvas x:Name="DirectivePointsCanvas"
Background="Transparent"
ClipToBounds="True"
AllowDragging="True"
AllowDragOutOfView="True"
Focusable="false"
Width="{Binding ElementName=MainMapImage, Path=ActualWidth}"
Height="{Binding ElementName=MainMapImage, Path=ActualHeight}"
MouseMove="DirectivePointsCanvas_MouseMove"
/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:DirectivePoint}">
<Ellipse Height="10"
Width="10"
StrokeThickness="2"
Fill="Yellow"
Stroke="Black"
Focusable="True"
Tag="{Binding Path=ID}"
MouseDown="Ellipse_MouseDown"
PreviewMouseDown="Ellipse_PreviewMouseDown"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Top" Value="{Binding Path=Location.Y}" />
<Setter Property="Canvas.Left" Value="{Binding Path=Location.X}" />
<Setter Property="Canvas.ZIndex" Value="99" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
我错过了什么?谢谢你的帮助!