双击WPF形状事件

问题描述 投票:1回答:2

我试图在双击WPF表单上的Ellipse后捕获一个事件。我不确定这样做的最佳做法是什么,因为WPF System.Windows.Shapes不包含双击事件。

我尝试捕获正常的鼠标按钮,点击次数为2。

    private void SetupProjectsCOEllipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //If double clicked
        if (e.ClickCount == 2)
        {
            PopupEntityDetails(this, ProjectsContext, LocalUser, TreeSetup.SelectedItem);
        }
    }
c# wpf events shapes
2个回答
2
投票

我已经设法通过使用ContentControl获得我想要的东西:

<ContentControl MouseDoubleClick="Ellipse_DoubleClick">
    <Ellipse Name="SetupProjectsCOEllipse" Width="10" Height="10"/>
</ContentControl>

0
投票

MouseDown应该可以正常工作,如果不是这样的话,那么视觉中的某个地方的父母就会阻止他从隧道中再次冒泡。这也解释了为什么在ContentControl中包裹形状“修复”它。

下次使用PreviewMouseDown代替。那是冒泡的事件,所以你有机会在它被截获之前抓住它。

© www.soinside.com 2019 - 2024. All rights reserved.