Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
ButtonBase Class
 ClickMode Property

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
ButtonBase..::.ClickMode Property

Gets or sets when the Click event occurs.

Namespace:  System.Windows.Controls.Primitives
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Property ClickMode As ClickMode
    Get
    Set
Visual Basic (Usage)
Dim instance As ButtonBase
Dim value As ClickMode

value = instance.ClickMode

instance.ClickMode = value
C#
public ClickMode ClickMode { get; set; }
XAML Attribute Usage
<button ClickMode="ClickMode"/>

Property Value

Type: System.Windows.Controls..::.ClickMode
When the Click event occurs. The default value is ClickMode..::.Release.

Dependency property identifier field: ClickModeProperty

Use this property to set what type of user interaction is required to raise a Click event. When a button's click mode is Hover, the Click event cannot be raised by using the keyboard.

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.

Visual Basic
Private Sub OnClick1(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn1.Foreground = New SolidColorBrush(Colors.Blue)
    text1.Text = "Click event handled on Hover."
    text2.Text = ""
    text3.Text = ""
End Sub

Private Sub OnClick2(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn2.Foreground = New SolidColorBrush(Colors.Green)
    text1.Text = ""
    text2.Text = "Click event handled on Press."
    text3.Text = ""
End Sub

Private Sub OnClick3(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn1.Foreground = New SolidColorBrush(Colors.Green)
    btn2.Foreground = New SolidColorBrush(Colors.Blue)
    text1.Text = ""
    text2.Text = ""
    text3.Text = "Click event handled on Release."
End Sub

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

void OnClick2(object sender, RoutedEventArgs e)
{
    btn2.Foreground = new SolidColorBrush(Colors.Green);
    text1.Text = "";
    text2.Text = "Click event handled 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 handled on Release.";
}

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="Button Demonstration" Margin="5,20,10,15"
            FontFamily="Verdana" FontSize="18" FontWeight="Bold"
            Foreground="#FF5C9AC9" Grid.Row="0" Grid.ColumnSpan="2"/>

        <Button x:Name="btn1" Grid.Row="1" Margin ="5" 
            HorizontalAlignment="Left"
            Foreground="Green" Width="120" Click="OnClick1" 
            Content="Hover to Click" ClickMode="Hover" />
        <TextBlock x:Name="text1" Grid.Row="1" Grid.Column="1" 
            Margin ="0,8,0,0" />

        <Button x:Name="btn2" Grid.Row="2" Margin ="5,5,5,5" 
            HorizontalAlignment="Left" 
            Foreground="Blue" Width="120" Click="OnClick2" 
            Content="Press to Click" ClickMode="Press" />
        <TextBlock x:Name="text2" Grid.Row="2" Grid.Column="1" 
            Margin="0,8,0,0" />

        <Button x:Name="btn3" Grid.Row="3" Margin ="5,5,5,5" 
            HorizontalAlignment="Left"
            Click="OnClick3" Width="120" Content="Reset" 
            ClickMode="Release"/>
        <TextBlock x:Name="text3" Grid.Row="3" Grid.Column="1" 
            Margin ="0,8,0,0" />


...


        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="Button Demonstration" Margin="5,20,10,15"
            FontFamily="Verdana" FontSize="18" FontWeight="Bold"
            Foreground="#FF5C9AC9" Grid.Row="0" Grid.ColumnSpan="2"/>

        <Button x:Name="btn1" Grid.Row="1" Margin ="5" 
            HorizontalAlignment="Left"
            Foreground="Green" Width="120" Click="OnClick1" 
            Content="Hover to Click" ClickMode="Hover" />
        <TextBlock x:Name="text1" Grid.Row="1" Grid.Column="1" 
            Margin ="0,8,0,0" />

        <Button x:Name="btn2" Grid.Row="2" Margin ="5,5,5,5" 
            HorizontalAlignment="Left" 
            Foreground="Blue" Width="120" Click="OnClick2" 
            Content="Press to Click" ClickMode="Press" />
        <TextBlock x:Name="text2" Grid.Row="2" Grid.Column="1" 
            Margin="0,8,0,0" />

        <Button x:Name="btn3" Grid.Row="3" Margin ="5,5,5,5" 
            HorizontalAlignment="Left"
            Click="OnClick3" Width="120" Content="Reset" 
            ClickMode="Release"/>
        <TextBlock x:Name="text3" Grid.Row="3" Grid.Column="1" 
            Margin ="0,8,0,0" />

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker