开发者

Disable DoubleClicks

I'm trying to disable double clicks on but开发者_如何转开发tons 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜