vb.net INotifyPropertyChanged 及 ICommand

 

 

Imports System.ComponentModel
''' <summary>
''' 属性变化后通知UI
''' </summary>
''' <remarks></remarks>
Public Class NotificationObject
    Implements INotifyPropertyChanged

    Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

    Public Sub RaisePropertyChanged(PropertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
    End Sub
End Class

''' <summary>
''' 绑定命令属性
''' </summary>
''' <remarks></remarks>
Class DelegateCommand
    Implements ICommand
    Public ExecuteCommand As Action(Of Object) = Nothing
    Public CanExecuteCommand As Func(Of Object, Boolean) = Nothing

    Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
        If IsNothing(Me.CanExecuteCommand) Then
            Return True
        Else
            Return Me.CanExecute(parameter)
        End If
    End Function

    Public Event CanExecuteChanged(sender As Object, e As EventArgs) Implements ICommand.CanExecuteChanged

    Public Sub Execute(parameter As Object) Implements ICommand.Execute
        If Not IsNothing(Me.ExecuteCommand) Then
            Me.ExecuteCommand(parameter)
        End If
    End Sub

    Public Sub RaiseCanExcuteChanged()
        If Not IsNothing(Me.CanExecuteCommand) Then
            RaiseEvent CanExecuteChanged(Me, EventArgs.Empty)
        End If
    End Sub
End Class

 

posted @ 2019-06-04 09:27  蜜铀  阅读(255)  评论(1编辑  收藏  举报