如何在 WPF 中编写 throbber(“正在加载”或“等待”图形)?

发布于 2024-10-03 04:41:09 字数 509 浏览 3 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

兲鉂ぱ嘚淚 2024-10-10 04:41:09

在我看来,你在这里问了一堆不同的问题。所以,虽然我通常不喜欢零碎的回复,但这里是:

但也许有某种共享
免费使用的通用图形
不知道这到底是什么
东西叫什么,我不知道
用于搜索的名称或短语
一。他们叫什么?

我确信网络上有您可以使用的免版税图片。我可能会搜索“忙碌光标”甚至“沙漏”,因为直到最近,这就是主要操作系统呈现它们的方式。

另外,也许已经有一些东西了
构建到 WPF 或 WCF 甚至 MVVM 中
使用这个。有吗?

首先,我们最好明确一下我们的术语:

  • MVVM 没有“内置”任何东西,因为它是一种编程模式,而不是一个框架。有很多实现,但我不知道是否有特定的图形元素。可能是!
  • WCF 是 Windows Communication Foundation,其库几乎肯定不包含任何图形元素。
  • WPF 是 Windows Presentation Foundation,您可以在其中找到(或定义您自己的)图形元素。它确实包含一个进度条,但是尽管您可以自定义任何 WPF 控件的外观,但它实际上是为了显示从起点到终点的进度。那可能不是你想要的。不过,WPF 当然可以显示动画图像。这是SO 中用于显示动画 GIF 的示例< /a>.

此外,也许有人已经制定了
制作整个表单或页面的方法
显示时呈灰色且处于非活动状态
旋转圈子一直善良
足以分享它。这是真的吗?

几乎可以肯定。同样,您可以在这里采取多种方法。例如,此问题中提到了其中一些。搜索“覆盖”或“启动画面”可能会为您指明正确的方向。简而言之(在 WPF 中):

  • 使页面“非活动”
  • 通过设置其控件的 Inactive 属性和/或捕获 Preview(Key|Mouse)Down 事件“灰显”, 通过在页面顶部显示半透明元素(例如 GridRectangle)来显示页面。根据您执行此操作的方式,它也可能会处理使底层控件“不活动”(不要引用我的话,但我相信像矩形这样的元素会拦截鼠标单击,因此用户无法单击其下方的控件...)

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:

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?

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.

Also, maybe there is something already
build into WPF or WCF or even MVVM
that uses this. Is there?

First, we'd better get clear on our terms:

  • MVVM does not have anything "built into" it, because it's a programming pattern, not a framework. There are plenty of implementations of it, but I don't know if any contain specific graphical elements. Could be!
  • WCF is Windows Communication Foundation, and its libraries almost certainly don't contain any graphical elements.
  • WPF is Windows Presentation Foundation, and that's where you will find (or define your own) graphical elements. It does contain a progress bar, but although you can customize the look of any WPF control, it's really meant to show progress from a starting point to an endpoint. That might not be what you want. WPF can certainly display animated images, though. Here's an example from SO for displaying animated GIFs.

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?

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):

  • Make the page "inactive" by setting its controls' Inactive properties and / or trapping Preview(Key|Mouse)Down events
  • "Gray out" the page by displaying a translucent element, such as a Grid or Rectangle 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...)
提笔落墨 2024-10-10 04:41:09

使用后台工作程序,对于 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.

夜夜流光相皎洁 2024-10-10 04:41:09

我不确定,只是一个想法。显示包含旋转圆圈的透明模式窗口,直到后台线程加载数据。当数据加载时。关闭模态窗口。

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.

一曲琵琶半遮面シ 2024-10-10 04:41:09

您可以简单地使用附加属性

这是一篇包含完整示例代码的帖子(只有几个类)

您的主 WPF 窗口看起来就像这样:

    <Window.Resources>
    <CollectionViewSource x:Key="DataList" Source="{Binding TestData}"  />
</Window.Resources>
<Grid Background="AliceBlue" app:AsyncNotifier.Trigger="{Binding IsDataLoading}" 
      app:AsyncNotifier.SpinnerText="Loading...">
    <TabControl Grid.RowSpan="2">
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ListBox ItemsSource="{Binding 
                    Source={StaticResource DataList}}" />
                <Button Content="Do Update" HorizontalAlignment="Left" Command="{Binding LoadData}"
                        VerticalAlignment="Top" Width="75" Grid.Row="1" Margin="0,5" />
            </Grid>
        </TabItem>
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5"/>
        </TabItem>
    </TabControl>
</Grid>

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:

    <Window.Resources>
    <CollectionViewSource x:Key="DataList" Source="{Binding TestData}"  />
</Window.Resources>
<Grid Background="AliceBlue" app:AsyncNotifier.Trigger="{Binding IsDataLoading}" 
      app:AsyncNotifier.SpinnerText="Loading...">
    <TabControl Grid.RowSpan="2">
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ListBox ItemsSource="{Binding 
                    Source={StaticResource DataList}}" />
                <Button Content="Do Update" HorizontalAlignment="Left" Command="{Binding LoadData}"
                        VerticalAlignment="Top" Width="75" Grid.Row="1" Margin="0,5" />
            </Grid>
        </TabItem>
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5"/>
        </TabItem>
    </TabControl>
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文