How can I bind key gestures in Caliburn.Micro?

前端 未结 5 1315
一个人的身影
一个人的身影 2020-12-30 08:47

How can I get Caliburn.Micro to map a key gesture to an action method on my ViewModel?

For example, I want to implement a tabbed interface, and I want my ShellViewMo

5条回答
  •  余生分开走
    2020-12-30 09:26

    If you marshal a command through the View to the View Model you can control the CanExecute from the View Model. I've been using this method in multiple Caliburn projects. Might not be as "slick" as using Interactivity, but CanExecute works.

    
    
      
        
      
    
      

    In your View class, you wire the command to the View Model which is referenced in the MyView.DataContext property.

    Class MyView
    
        Public Property RefreshCommand As _
        New RelayCommand(AddressOf Refresh,
                         Function()
                             If ViewModel Is Nothing Then
                                 Return False
                             Else
                                 Return ViewModel.CanRefresh
                             End If
                         End Function)
    
        Private Sub Refresh()
            ViewModel.Refresh()
        End Sub
    
        Private ReadOnly Property ViewModel As MyViewModel
            Get
                Return DirectCast(DataContext, MyViewModel)
            End Get
        End Property
    
    End Class
    

提交回复
热议问题