【发布时间】:2011-04-16 09:45:15
【问题描述】:
如果我使用文件 .cur 或 .ani 来替换鼠标光标,我只需要显示一个自定义控件(带有旋转指针的时钟)并用它来替换鼠标光标 Me.CUrsor = New Cursor(".ani 文件的绝对路径") 没有问题:我可以在一个过程中改变光标:但是动画质量很差,而且,还有其他原因,我更喜欢使用我的小用户控件。问题是,如果我写:
Me.gridScreen.Visibility = Visibility.Visible
' 一些大约需要 1 秒的操作
Me.gridScreen.Visibility = Visibility.Hidden
(gridScreen 是包含用户控件的网格)
显然我什么也看不到,因为 UI 的更新发生在程序结束时。我已经尝试过 Me.UpdateLayout(),但它不起作用。
我尝试过以多种方式使用拆包器,但都没有用 :-(
这是我失败的尝试:
(uCurClock是用户控件,gridScreen是一个放置在窗口顶层的Grid,背景透明,包含用户控件)
Private Sub showClock()G
Dim thread = New System.Threading.Thread(AddressOf showClockIntermediate)
thread.Start()
End Sub
Private Sub hideClock()
Dim thread = New System.Threading.Thread(AddressOf hideClockIntermediate)
thread.Start()
End Sub
Private Sub showClockIntermediate()
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New Action(AddressOf showClockFinale))
End Sub
Private Sub hideClockIntermediate()
Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New Action(AddressOf hideClockFinale))
End Sub
Private Sub showClockFinale()
Dim pt As Point = Mouse.GetPosition(Nothing)
Me.uCurClock.Margin = New Thickness(pt.X - 9, pt.Y - 9, 0, 0)
Me.gridScreen.Visibility = Visibility.Visible
Me.Cursor = Cursors.None
Me.UpdateLayout()
End Sub
Private Sub hideClockFinale()
Me.gridScreen.Visibility = Visibility.Hidden
Me.Cursor = Cursors.Arrow
Me.UpdateLayout()
End Sub
Private Sub u_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseMove
Dim pt As Point = e.GetPosition(Nothing)
Me.uCurClock.Margin = New Thickness(pt.X - 9, pt.Y - 9, 0, 0)
e.Handled = True
End Sub
Private Sub u_MouseEnter(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseEnter
Me.uCurClock.Visibility = Visibility.Visible
e.Handled = True
End Sub
Private Sub u_MouseLeave(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles gridScreen.MouseLeave
Me.uCurClock.Visibility = Visibility.Hidden
e.Handled = True
End Sub
皮莱吉
【问题讨论】:
标签: wpf multithreading user-interface refresh