如何在 WPF 中编写 throbber(“正在加载”或“等待”图形)?
如何在 WPF 中编写“正在加载”或“等待”图形的代码?
如果某人的页面需要加载大量信息(通常在 Flash 网站上),您会看到某种圆形旋转,这通常意味着正在加载大量数据,用户需要等待。
这不仅仅是一个好的效果。它具有现实世界的应用和重要性。如果某人打开一个没有此图形的表单、页面或窗口,而是看到一个应该显示信息的表单,但看到的是空白字段,那么他的第一个想法可能是没有信息可看。即使光标转到等待模式,这也可能是正确的。与可能处于某种旋转状态的光标相比,广阔的空旷领域将更具有图像的存在性和压倒性。
我想我可以把一些东西放在一起。我想我可以呈现一个旋转圆圈的 gif,该圆圈在开始时显示,然后在调用所有数据加载方法后隐藏。但也许有某种共享的通用图形可以免费使用,并且在不确切知道这个东西叫什么的情况下,我不知道使用什么名称或短语来搜索它。他们叫什么?
另外,也许 WPF 甚至 MVVM 中已经内置了一些使用它的东西。有没有?另外,也许有人已经找到了一种方法,可以在显示旋转圆圈时使整个表单或页面变灰且不活动,并且很友善地分享它。这是真的吗?
How do you code that "loading" or "waiting" graphic in WPF?
If someone had a page that requires loading a lot information, typically on a flash web site, you see a circle spinning of some sort that universally means that there is a lot of data that is being loaded and the user needs to wait.
This is more than just a nice effect. It has real world application and importance. If someone opens a form or page or window that does not have this graphic and instead sees a form that should have information displayed but instead sees blank fields, his first notiion might rightly be that there is no information to be seen. This could be true even if the cursor turns to a waiting mode. The vast fields of emptiness will be more present and overpowering of an image than a cursor that might be in some sort of spinning state.
I suppose I could throw something together. I suppose I could present a gif of a rotating circle that is shown at the beginning and then hidden once all the data loading methods have been called. But maybe there is some sort of shared common graphic to use for free and without knowing exactly what this thing is called, I do not know what name or phrase to use to search for one. What are they called?
Also, maybe there is something already build into WPF or even MVVM that uses this. Is there? Also, maybe someone has worked out a way to make the whole form or page gray and inactive while displaying a rotating circle and has been kind enough to share it. Is this true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在我看来,你在这里问了一堆不同的问题。所以,虽然我通常不喜欢零碎的回复,但这里是:
我确信网络上有您可以使用的免版税图片。我可能会搜索“忙碌光标”甚至“沙漏”,因为直到最近,这就是主要操作系统呈现它们的方式。
首先,我们最好明确一下我们的术语:
几乎可以肯定。同样,您可以在这里采取多种方法。例如,此问题中提到了其中一些。搜索“覆盖”或“启动画面”可能会为您指明正确的方向。简而言之(在 WPF 中):
Inactive
属性和/或捕获Preview(Key|Mouse)Down
事件“灰显”, 通过在页面顶部显示半透明元素(例如Grid
或Rectangle
)来显示页面。根据您执行此操作的方式,它也可能会处理使底层控件“不活动”(不要引用我的话,但我相信像矩形这样的元素会拦截鼠标单击,因此用户无法单击其下方的控件...)As I see it, you're sort of asking a bunch of different questions here. So, though I normally dislike the piecemeal reply, here it is:
I'm sure there are royalty-free images on the web that you could use. I would probably search for "busy cursor" or even "hourglass", since, up until recently, that's how the major operating systems rendered them.
First, we'd better get clear on our terms:
Almost certainly. Again, there are numerous approaches you could take here. Some of them are mentioned in this question, for example. Searching for "overlays" or "splash screens" could point you in the right direction. In short (in WPF):
Inactive
properties and / or trappingPreview(Key|Mouse)Down
eventsGrid
orRectangle
over top of it. Depending on how you do this, it might handle making the underlying controls "inactive", as well (don't quote me on this, but I believe an element like a Rectangle will intercept mouse clicks, so the user can't click on controls underneath it...)使用后台工作程序,对于 wpf 中的圆形进度条,请参阅 http://www.codeproject.com/Articles/49853/Better-WPF-Circular-Progress-Bar.aspx 非常好的一个。
Use a background worker, and for a circular progress bar in wpf, see http://www.codeproject.com/Articles/49853/Better-WPF-Circular-Progress-Bar.aspx for a very good one.
BackGroundWorker 线程是你的朋友。
http://msdn.microsoft.com/en-us/library /system.componentmodel.backgroundworker.aspx
BackGroundWorker thread is your friend.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
我不确定,只是一个想法。显示包含旋转圆圈的透明模式窗口,直到后台线程加载数据。当数据加载时。关闭模态窗口。
I am not sure, just an idea. Show a transparent modal window that contains spinning circle until the data is loaded by the background thread. When the data is loaded. close the modal window.
您可以简单地使用附加属性
这是一篇包含完整示例代码的帖子(只有几个类)
您的主 WPF 窗口看起来就像这样:
You could simply use attached properties
Here's a post with complete sample code (just a couple of classes)
Your main WPF Windows would simply look something like this: