有没有简单的方法来设置WPF状态栏的文字? [英] Is there no simple way to set WPF StatusBar text?

查看:1226
本文介绍了有没有简单的方法来设置WPF状态栏的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望让用户等待,而我的程序做的工作一点点片刻之前设置我的状态条TextBlock的文本。

I want to set the Text of a TextBlock in my StatusBar before making the user wait for a short moment while my program does a little bit of work.

Aparently,而不是做一个可爱的小功能,这样的(这不工作):

Aparently, instead of doing a nice little function like this (which does not work):

Function Load(ByVal Id As Guid) As Thing
    Cursor = Cursors.Wait
    TextBlockStatus.Text = "Loading..."
    TextBlockStatus.UpdateLayout()
    Dim Found = From t In db.Thing _
                Where t.Id = Id _
                Select t
    TextBlockStatus.Text = String.Empty
    Cursor = Cursors.Arrow
    Return Found
End Function

我要改用这个畸形的:

I have to instead use this monstrosity:

Private WithEvents LoadWorker As BackgroundWorker

Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    InitializeLoadWorker()
End Sub

Private Sub InitializeLoadWorker()
    LoadWorker = New BackgroundWorker
    LoadWorker.WorkerSupportsCancellation = False
    LoadWorker.WorkerReportsProgress = False
    AddHandler LoadWorker.DoWork, AddressOf LoadBackgroundWorker_DoWork
    AddHandler LoadWorker.RunWorkerCompleted, AddressOf LoadBackgroundWorker_RunWorkerCompleted
End Sub

Sub Load(ByVal Id As Guid)
    Cursor = Cursors.Wait
    LoadWorker.RunWorkerAsync(Argument)
End Sub

Private Sub LoadBackgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    Dim Worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
    Dim Id As Guid = DirectCast(e.Argument, Guid)
    e.Result = From t In db.Thing _
               Where t.Id = Id _
               Select t
End Sub

Private Sub LoadBackgroundWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
    TextBlockStatus.Text = String.Empty
    Cursor = Cursors.Arrow
    Dim Found As Thing = DirectCast(e.Result, Thing)
    'now do something with the found thing here instead of where Load() is called.'
End Sub

和的load()函数现在是一个子!

And the Load() Function is now a Sub!!

必须有一个更好的办法来处理这​​样一个简单的情况。这并不需要是异步

There must be a better way to handle such a simple situation. This doesn't need to be asynchronous.

推荐答案

有一个在这个问题:的显示等待屏幕在WPF

Have a look at this question: Display Wait Screen in WPF.

接受的答案有做什么我想你想,如果没有后台工作类的方法。

The accepted answer has a way of doing what I think you want, without a Background worker class.

这是在回答其他问题的联系,这可能为VB.NET工作(我还没有尝试过,虽然)

From the link in the answer to the other question, this might work for VB.NET (I haven't tried it though)

Public Sub AllowUIToUpdate()

    Dim frame As New DispatcherFrame()

    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, New DispatcherOperationCallback(AddressOf JunkMethod), frame)

    Dispatcher.PushFrame(frame)

End Sub

Private Function JunkMethod(ByVal arg As Object) As Object

    DirectCast(arg, DispatcherFrame).Continue = False
    Return Nothing

End Function

这篇关于有没有简单的方法来设置WPF状态栏的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆