#316 – Changing the ClickMode of a Button

A standard Button in WPF (and in Windows in general) performs some action when you click it.  Traditionally “click it” has meant “depress and then release the left mouse button”.  The action associated with the button typically occurs only on the release of the button.

In WPF, you can change when the button fires its Click event by using the Button.ClickMode property.

  • ClickMode.Release – fires when you release the mouse button  (Default)
  • ClickMode.Press – fires when you press the mouse button
  • ClickMode.Hover – fires when you hover over the button
<StackPanel>
    <Button Content="Release" ClickMode="Release" Height="30" Width="100" Margin="15" Click="Button_Click"/>
    <Button Content="Press" ClickMode="Press" Height="30" Width="100" Margin="15" Click="Button_Click"/>
    <Button Content="Hover" ClickMode="Hover" Height="30" Width="100" Margin="15" Click="Button_Click"/>
    <Label Name="lblInfo" Margin="15"/>
</StackPanel>

 

        private int clickNum = 1;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            lblInfo.Content = string.Format("Click {0}, Mode {1}", clickNum++, b.ClickMode.ToString());
        }

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: