当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET InputBinding类代码示例

本文整理汇总了VB.NET中System.Windows.Input.InputBinding的典型用法代码示例。如果您正苦于以下问题:VB.NET InputBinding类的具体用法?VB.NET InputBinding怎么用?VB.NET InputBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InputBinding类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: New

' Create a class that implements ICommand and accepts a delegate. 
Public Class SimpleDelegateCommand
    Implements ICommand

    ' Specify the keys and mouse actions that invoke the command. 
    Private _GestureKey As Key
    Private _GestureModifier As ModifierKeys
    Private _MouseGesture As MouseAction

    Public Property GestureKey() As Key
        Get
            Return _GestureKey
        End Get
        Set(ByVal value As Key)
            _GestureKey = value
        End Set
    End Property

    Public Property GestureModifier() As ModifierKeys
        Get
            Return _GestureModifier
        End Get
        Set(ByVal value As ModifierKeys)
            _GestureModifier = value
        End Set
    End Property

    Public Property MouseGesture() As MouseAction
        Get
            Return _MouseGesture
        End Get
        Set(ByVal value As MouseAction)
            _MouseGesture = value
        End Set
    End Property

    Private _executeDelegate As Action(Of Object)

    Public Sub New(ByVal executeDelegate As Action(Of Object))
        _executeDelegate = executeDelegate
    End Sub

    Public Sub Execute(ByVal parameter As Object) _
        Implements ICommand.Execute

        _executeDelegate(parameter)
    End Sub

    Public Function CanExecute(ByVal parameter As Object) As Boolean _
        Implements ICommand.CanExecute

        Return True
    End Function

    Public Event CanExecuteChanged As EventHandler _
        Implements ICommand.CanExecuteChanged
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Input,代码行数:57,代码来源:InputBinding

示例2: InitializeCommand

Public ReadOnly Property ChangeColorCommand() As SimpleDelegateCommand
    Get
        Return _changeColorCommand
    End Get
End Property

Private _changeColorCommand As SimpleDelegateCommand
Private originalColor As Brush, alternateColor As Brush

Private Sub InitializeCommand()
    originalColor = Me.Background

    _changeColorCommand = New SimpleDelegateCommand(Function(x) Me.ChangeColor(x))

    DataContext = Me
    _changeColorCommand.GestureKey = Key.C
    _changeColorCommand.GestureModifier = ModifierKeys.Control
    _changeColorCommand.MouseGesture = MouseAction.RightClick
End Sub

' Switch the Background color between 
' the original and selected color. 
Private Function ChangeColor(ByVal colorString As Object) As Integer

    If colorString Is Nothing Then
        Return 0
    End If

    Dim newColor As Color = DirectCast(ColorConverter.ConvertFromString(DirectCast(colorString, [String])), Color)

    alternateColor = New SolidColorBrush(newColor)

    If Brush.Equals(Me.Background, originalColor) Then
        Me.Background = alternateColor
    Else
        Me.Background = originalColor
    End If

    Return 0
End Function
开发者ID:VB.NET开发者,项目名称:System.Windows.Input,代码行数:40,代码来源:InputBinding


注:本文中的System.Windows.Input.InputBinding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。