ButtonBase.ClickMode property

Applies to Windows and Windows Phone

Gets or sets a value that indicates when the Click event occurs, in terms of device behavior.

Syntax


public ClickMode ClickMode { get; set; }


<button ClickMode="clickModeMemberName"/>


XAML Values

clickModeMemberName

A named constant of the ClickMode enumeration, such as Hover.

Property value

Type: ClickMode

A value of the enumeration that indicates when the Click event occurs.

Examples

The following example shows three buttons that respond to clicks in three different ways based on their ClickMode property value.

  • Hover - When the mouse pointer hovers over the first button, the foreground color of the button changes.

  • Press - When the left mouse button is pressed while over the second button, the foreground color of the button changes.

  • Release - When the mouse button is pressed and released while over the third button, the button resets the foreground color of the other two buttons to their original color.


   <StackPanel x:Name="LayoutRoot" Margin="10">
     <Button x:Name="btn1" Content="Hover to Click"
             Click="OnClick1" ClickMode="Hover"
             Margin="5" Width="150"
             HorizontalAlignment="Left"
             Foreground="Green"/>
     <TextBlock x:Name="text1" Margin="5,8,0,0" />
     
     <Button x:Name="btn2" Content="Press to Click"
             Click="OnClick2" ClickMode="Press"
             Margin="5,5,5,5" Width="150" 
             HorizontalAlignment="Left" 
             Foreground="Blue"/>
     <TextBlock x:Name="text2" Margin="5,8,0,0" />
     
     <Button x:Name="btn3" Content="Reset"
             Click="OnClick3" ClickMode="Release"
             Margin="5,5,5,5" Width="150"
             HorizontalAlignment="Left"/>
     <TextBlock x:Name="text3" Margin="5,8,0,0" />
   </StackPanel>



void OnClick1(object sender, RoutedEventArgs e)
{
    btn1.Foreground = new SolidColorBrush(Colors.Blue);
    text1.Text = "Click event occurs on Hover.";
    text2.Text = "";
    text3.Text = "";
}

void OnClick2(object sender, RoutedEventArgs e)
{
    btn2.Foreground = new SolidColorBrush(Colors.Green);
    text1.Text = "";
    text2.Text = "Click event occurs on Press.";
    text3.Text = "";
}

void OnClick3(object sender, RoutedEventArgs e)
{
    btn1.Foreground = new SolidColorBrush(Colors.Green);
    btn2.Foreground = new SolidColorBrush(Colors.Blue);
    text1.Text = "";
    text2.Text = "";
    text3.Text = "Click event occurs on Release.";
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls.Primitives
Windows::UI::Xaml::Controls::Primitives [C++]

Metadata

Windows.winmd

See also

ButtonBase
Button

 

 

Show:
© 2014 Microsoft. All rights reserved.