ClickMode 枚举

定义

指定何时应为控件引发 Click 事件。

public enum class ClickMode
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
enum class ClickMode
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public enum ClickMode
Public Enum ClickMode
<object property="enumMemberName"/>
继承
ClickMode
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

字段

Hover 2

指定当鼠标指针移动到控件上时应引发 Click 事件。

Press 1

指定当按下鼠标按钮且鼠标指针位于控件上方时,应引发 Click 事件。 如果使用键盘,则指定在按下空格键或 Enter 键且控件具有键盘焦点时应引发 Click 事件。

Release 0

指定在按下并释放鼠标左键且鼠标指针位于控件上方时,应引发 Click 事件。 如果使用键盘,则指定在按下并释放空格键或 Enter 键且控件具有键盘焦点时,应引发 Click 事件。

示例

以下示例演示 ClickMode 枚举。

  • 悬停 - 鼠标指针悬停在第一个按钮上时,按钮的前景色会更改。
  • 按 - 当鼠标左键位于第二个按钮上方时,按钮的前景色会更改。
  • 释放 - 当鼠标按钮按下并松开时,在第三个按钮上方,该按钮会将其他两个按钮的前景色重置为其原始颜色。
<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(Windows.UI.Colors.Blue);
    text1.Text = "Click event occurs on Hover.";
    text2.Text = "";
    text3.Text = "";
}

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

void OnClick3(object sender, RoutedEventArgs e)
{
    btn1.Foreground = new SolidColorBrush(Windows.UI.Colors.Green);
    btn2.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
    text1.Text = "";
    text2.Text = "";
    text3.Text = "Click event occurs on Release.";
}
Private Sub OnClick1(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn1.Foreground = New SolidColorBrush(Windows.UI.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(Windows.UI.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(Windows.UI.Colors.Green)
    btn2.Foreground = New SolidColorBrush(Windows.UI.Colors.Blue)
    text1.Text = ""
    text2.Text = ""
    text3.Text = "Click event handled on Release."
End Sub

适用于