在WPF中应用程序忙时阻止用户操作排队

时间:2019-04-14 02:32:15

标签: wpf vb.net mvvm

我已从此链接转换了以下vb.net代码:WPF - prevent user actions queuing-up while application is busy

ViewModel:

Class MainWindow

Private _appIdle As Boolean = True

Private Sub Hooks_OperationStarted(ByVal sender As Object, ByVal e As Windows.Threading.DispatcherHookEventArgs)
    ApplicationIdle = False
End Sub

Private Sub Hooks_OperationCompleted(ByVal sender As Object, ByVal e As Windows.Threading.DispatcherHookEventArgs)
    ApplicationIdle = True
End Sub

Public Property ApplicationIdle As Boolean
    Get
        Return _appIdle
    End Get
    Set(ByVal value As Boolean)
        _appIdle = value
        RaisePropertyChanged("ApplicationIdle")
    End Set
End Property

Public Sub MainWindowViewModel()
    Application.Current.Dispatcher.Hooks.OperationStarted += AddressOf Hooks_OperationStarted
    Application.Current.Dispatcher.Hooks.OperationCompleted += AddressOf Hooks_OperationCompleted
End Sub

End Class

MainWindow xaml:

IsHitTestVisible="{Binding ApplicationIdle}"

但是您在这张图片中看到了一些错误:https://prnt.sc/nbn55h

请告诉我如何解决该错误?

错误提示:

  

未声明“ RaisePropertyChanged”。由于以下原因可能无法访问   其保护级别。

注意::我正在使用.NET 4.5

支持链接: https://jeremybytes.blogspot.com/2016/01/the-evolution-of-inotifypropertychanged.html

1 个答案:

答案 0 :(得分:0)

Class MainWindow
   Implements System.ComponentModel.INotifyPropertyChanged

   Public Event RaisePropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

   Private _appIdle As Boolean = True

   Private Sub Hooks_OperationStarted(ByVal sender As Object, ByVal e As Windows.Threading.DispatcherHookEventArgs)
      ApplicationIdle = False
   End Sub

   Private Sub Hooks_OperationCompleted(ByVal sender As Object, ByVal e As Windows.Threading.DispatcherHookEventArgs)
      ApplicationIdle = True
   End Sub

   Public Property ApplicationIdle As Boolean
      Get
         Return _appIdle
      End Get
      Set(ByVal value As Boolean)
         _appIdle = value
         RaiseEvent RaisePropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("ApplicationIdle"))
      End Set
   End Property

   Public Sub MainWindowViewModel()
      AddHandler Application.Current.Dispatcher.Hooks.OperationStarted, AddressOf Hooks_OperationStarted
      AddHandler Application.Current.Dispatcher.Hooks.OperationCompleted, AddressOf Hooks_OperationCompleted
   End Sub

End Class