Wpf 在后台线程上填充面板时未触发CanExcuteOutDevenHandler
WPF窗口的CommandBinding上绑定的按钮: XAML CanExecuteRouteEvent的处理程序定义如下:Wpf 在后台线程上填充面板时未触发CanExcuteOutDevenHandler,wpf,vb.net,multithreading,routed-events,Wpf,Vb.net,Multithreading,Routed Events,WPF窗口的CommandBinding上绑定的按钮: XAML CanExecuteRouteEvent的处理程序定义如下: Private Sub hndlCmdRenderData(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs) '... End Sub '(3) Private Sub hndlCmdCanRenderData(ByVal sender As Object, ByVal e As Ca
Private Sub hndlCmdRenderData(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
'...
End Sub
'(3)
Private Sub hndlCmdCanRenderData(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
e.CanExecute = pnlData.Children.Count > 1
End Sub
这意味着,如果主面板包含数据,例如另一个UIElement,则该按钮处于活动状态。面板的UiElement填充在背景线程上
Private Sub renderData()
_clearPanel()'clears pnlData (1)
m_UielementToLoad = New ctlPDFViewer()'the UiElement, a global variable
Dim rep As New clsPDFRenderer(Me.Dispatcher)'the class performing the data stuff in background thread
AddHandler rep.ScreenDone, AddressOf _threadScreenRendered'Address of the sub invoked in thread
m_ActiveScreenThread = New Threading.Thread(AddressOf rep.Post)
m_ActiveScreenThread.Start()
End Sub
后台线程末尾调用的子线程定义如下:
Private Sub hndlCmdRenderData(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
'...
End Sub
'(3)
Private Sub hndlCmdCanRenderData(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
e.CanExecute = pnlData.Children.Count > 1
End Sub
私有子线程ScreenRendered(发送者作为对象,屏幕作为字符串)
CType(m_UielementToLoad,ctlPDFViewer).SetDocumentData(screen)'全局UIElement由后台线程的数据填充
pnlData.Children.Add(m_UielementToLoad)'UIElement作为子元素添加到面板(2)
pnlData.Children(0).SetValue(DockPanel.DockProperty,Dock.Left)
端接头
如果面板数据已填充,则按钮处于活动状态。如果我启动子“renderData()”并执行第(1)行(清除面板),按钮将立即变为非活动状态-CanExecute处理程序(3)将被触发,线程将启动,子“threadScreenRendered(..”)将在最后被调用。面板被填满(2),但CanExecute处理程序(3)未被触发,按钮保持非活动状态。
仅在用鼠标单击一次后,按钮才会激活。
我看不出第(1)行和第(2)行之间有什么不对劲或区别
Private Sub renderData()
_clearPanel()'clears pnlData (1)
m_UielementToLoad = New ctlPDFViewer()'the UiElement, a global variable
Dim rep As New clsPDFRenderer(Me.Dispatcher)'the class performing the data stuff in background thread
AddHandler rep.ScreenDone, AddressOf _threadScreenRendered'Address of the sub invoked in thread
m_ActiveScreenThread = New Threading.Thread(AddressOf rep.Post)
m_ActiveScreenThread.Start()
End Sub