Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Use DoubleClickCommand in Xaml

0.00/5 (No votes)
1 Apr 2008 1  
Expose DoubleClick command from FrameworkUIElement

Introduction

Some classes like Button an MenuItem provided a property named Command which makes coding simplier, but most other classes do not provide same kind of functionality for each events.

I want to implement a Command for DoubleClick, I did tried Googled, there are some solution included using EventSetter or something like that, but it is too complicated for me, so I developed a new control just for doing that.

Background

The control is very simple...(96 lines), it is actually a DockPanel which you can used to host your control (which implement doubleclick).

Using the code

<Window x:Class="WPF_DirectoryLister_DMVVM.Window1"
        xmlns:control="clr-namespace:QuickZip.Windows.Controls"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="600">
         
        <Grid>
        <control:TrapDoubleClick>
            <Label control:TrapDoubleClick.Command="ApplicationCommands.Help">
                DoubleClickMe
            </Label>
        </control:TrapDoubleClick>
        </Grid>
</Window>         

Points of Interest

Took me a while to figure out, if you want to override OnMouseLeftButtonDown method, you will have to set Control.AllowDrop to true.

History

04/02/08 Initial Release

Reference

DoubleClick on Framework Element

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here