Why doesn't WPF border control have a mousedoubleclick event?

前端 未结 3 591
-上瘾入骨i
-上瘾入骨i 2020-12-09 08:36

Why doesn\'t WPF border control have a mousedoubleclick event? I have a ItemsControl with some layout stuff in it for a DataTemplate. I want to handle the double click eve

相关标签:
3条回答
  • 2020-12-09 08:53

    Just use InputBindings.

    <Border>
        <Border.InputBindings>
            <MouseBinding MouseAction="LeftDoubleClick" Command="..."/>
        </Border.InputBindings>
    </Border>
    

    In general; avoid using events if not developing controls in WPF. Usually the usage of code behind based events is a strong indication for a MVVM Pattern break.

    0 讨论(0)
  • 2020-12-09 08:58

    MouseDoubleClick is declared on Control so you just need an instance of some Control in your ItemTemplate. The simplest thing to do is use the base Control class which doesn't have any other behavior and just give it a customized template with what's in your ItemTemplate now.

    <ItemsControl>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Control MouseDoubleClick="Control_MouseDoubleClick">
                    <Control.Template>
                        <ControlTemplate>
                            <Border>
                                <!--Other ItemTemplate stuff-->
                            </Border>
                        </ControlTemplate>
                    </Control.Template>
                </Control>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    0 讨论(0)
  • 2020-12-09 09:10

    Update: Sorry, my bad - late hour

    Inside your mouse button down event get ClickCount

     //  e.Handled = true;  optional
    
     if (e.ClickCount > 1)
     {
        // here comes double click and more :)
     }
    
    0 讨论(0)
提交回复
热议问题