Robert
Robert

Reputation: 6226

Disable DoubleClicks

I'm trying to disable double clicks on buttons and currently the only way I know is to handle the PreviewMouseDoubleClick and set the e.Handled = true.

Is there a way to do this in a button style? Or even better, disable double clicks application wide?

Upvotes: 1

Views: 2778

Answers (2)

Matt
Matt

Reputation: 4334

I would use an attached behavior (see this article). For example, say I create an attached behavior called DisableDoubleClickAttachedBehavior which handles the double click mouse event and sets e.Handled = true.

Then, you can nicely set the property via a style in XAML:

    <Style x:Key="DisableDoubleClickStyle">
        <Setter Property="p:DisableDoubleClickAttachedBehavior.Enabled" Value="True" />
    </Style>

    <Button Style="{StaticResource DoubleClickDisabledStyle}">Hi!</Button>

Or, you can override the style for all buttons (like you wanted):

    <Style TargetType="Button">
        <Setter Property="p:DisableDoubleClickAttachedBehavior.Enabled" Value="True" />
    </Style>

I tested this and it seems to work nicely.

Upvotes: 2

Tim
Tim

Reputation: 15237

I don't think it can be done in a style or application-wide. Best bet might be a class derived from Button that includes that event handler by default.

Upvotes: 1

Related Questions