WPF-某些鼠标事件不会触发

时间:2014-04-24 18:51:21

标签: c# wpf datatemplate itemscontrol mousedown

我使用ItemsControl来表示Canvas中贝塞尔曲线的控制点。我需要能够在MouseDown上捕获Ellipse事件以在移动期间检索光标位置,这样我就可以实时更新贝塞尔曲线。

MouseDownPreviewMouseDown有效。我已经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>

我错过了什么?谢谢你的帮助!

0 个答案:

没有答案