WPF VB 在别的线程里改UI
我利用了一个Timer来扫描Xbox 360控制器的按键
但是不知道怎么改动UI
错误信息:
An exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll but was not handled in user code
Additional information: The calling thread cannot access this object because a different thread owns it.
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Imports System.Timers
Imports System.Windows.Threading
Public Class XboxControllerStatus
Friend WithEvents Timer1 As Timer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Elapsed
Dim currentState As GamePadState = GamePad.GetState(PlayerIndex.One)
If currentState.IsConnected Then
If currentState.Buttons.LeftShoulder.Pressed Then
LB.Content = "Pressed"
Else
LB.Content = "LB"
End If
End If
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
跨线程修改UI线程需要使用UI线程的Dispatcher.BeginInvoke或Invoke方法。
看来碰vb的真的很少.我给你答案吧.
Imports System.Threading
Class MainWindow
End Class