如何在 wpf 屏幕上显示忙碌消息

发布于 2024-10-08 10:05:43 字数 387 浏览 2 评论 0原文

嘿, 我有一个基于 Prism4 的 WPF 应用程序。当执行缓慢的操作时,我想显示一个繁忙的屏幕。我将拥有大量屏幕,因此我尝试在框架中构建单个解决方案,而不是向每个屏幕添加忙碌指示器。

这些长时间运行的操作在后台线程中运行。这允许更新 UI(好),但不会阻止用户使用 UI(坏)。我想做的是用旋转拨号盘之类的东西覆盖一个控件,并让该控件覆盖整个屏幕(带有 DIV 的旧 HTML 技巧)。当应用程序繁忙时,控件将显示,从而阻止任何进一步的交互并显示旋转的东西。

为了进行设置,我想我可以将我的应用程序屏幕与旋转的东西(具有更大的 ZIndex)一起放在画布中,然后根据需要使旋转的东西可见。

然而,这变得越来越困难。画布似乎没有为此做好准备,我想我可能找错了对象。

我将不胜感激任何帮助。谢谢。

Hey,
I have a WPF application based on Prism4. When performing slow operations, I want to show a busy screen. I will have a large number of screens, so I'm trying to build a single solution into the framework rather than adding the busy indicator to each screen.

These long running operations run in a background thread. This allows the UI to be updated (good) but does not stop the user from using the UI (bad). What I'd like to do is overlay a control with a spinning dial sort of thing and have that control cover the entire screen (the old HTML trick with DIVs). When the app is busy, the control would display thus block any further interaction as well as showing the spinny thing.

To set this up, I thought I could just have my app screen in a canvas along with the spinny thing (with a greater ZIndex) then just make the spinny thing visible as required.

This, however, is getting hard. Canvases do not seem well set up for this and I think I might be barking up the wrong tree.

I would appreciate any help. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

清晰传感 2024-10-15 10:05:43

我已经用几个程序做到了这一点。简而言之:(

这对于 MVVM 来说是最简单的。自从我使用代码隐藏来做这样的事情以来已经很长时间了,我真的不能说是否有一个好的方法来做到这一点。)

  1. 在你的上创建一个边框主窗口。我通常将其设置为黑色,透明度为 50%。向其中添加一个网格,然后将您想要的任何内容放入其中以告诉用户它很忙。调整边框及其内部控件的大小以填充屏幕。
  2. 在主 ViewModel 上为 IsBusy 创建一个布尔值属性。初始化为False。将 Busy Border 的 Visibility 属性绑定到该属性。
  3. 接下来,为 Busy(Boolean) 到 Visibility 创建一个转换器类。将逻辑写入其中,以便当值为 True 时,可见性为 Visible,当值为 false 时,可见性折叠。 ( http://msdn.microsoft.com/en-us/library/system .windows.data.ivalueconverter.aspx )。
  4. 回到边界,将转换器添加到绑定中。将代码添加到每个页面或视图的 ViewModel 中,以回调该属性,并在其他线程繁忙时将其设置为 true。

科里

编辑:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">

<Grid>

    <Border BorderBrush="Black" BorderThickness="1" Background="#80000000" Visibility="Collapsed">
        <Grid>
            <TextBlock Margin="0" TextWrapping="Wrap" Text="Busy...Please Wait" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="26.667" FontWeight="Bold" Foreground="#7EFFFFFF"/>
        </Grid>
    </Border>

    <DockPanel x:Name="LayoutRoot">
        <CheckBox Content="CheckBox" VerticalAlignment="Top"/>
        <TextBlock TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
        <UserControl x:Name="ViewViewView"/>
    </DockPanel>
</Grid>

I have done this with a few programs. Here it is in a nutshell:

(This is easiest with MVVM. It has been so long since I used the codebehid for things like this I can't really say if there is a good way to do it.)

  1. Create a border on your Main Window. I usually make it black with a 50% transparency. Add a grid to it, and put whatever you want inside to tell users it is busy. Size the border and the controls inside it to fill the screen.
  2. Create a property on your main ViewModel for IsBusy as boolean. Initialize it as False. Bind the Visibility property of the Busy Border to that property.
  3. Next, make a converter class for Busy(Boolean) to Visibility. Write the logic into that so that when value is True, Then visibility is Visible, when value is false, visibility is collapsed. ( http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx ).
  4. Back on the border, add your converter to the binding. Add code to the ViewModel for each of your Pages or Views that calls back to that property and sets it to true when your other thread is busy.

Cory

Edit:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">

<Grid>

    <Border BorderBrush="Black" BorderThickness="1" Background="#80000000" Visibility="Collapsed">
        <Grid>
            <TextBlock Margin="0" TextWrapping="Wrap" Text="Busy...Please Wait" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="26.667" FontWeight="Bold" Foreground="#7EFFFFFF"/>
        </Grid>
    </Border>

    <DockPanel x:Name="LayoutRoot">
        <CheckBox Content="CheckBox" VerticalAlignment="Top"/>
        <TextBlock TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
        <UserControl x:Name="ViewViewView"/>
    </DockPanel>
</Grid>

淡紫姑娘! 2024-10-15 10:05:43

查看带有繁忙指示器的 WPF 工具包: https://github.com/xceedsoftware/wpftoolkit/维基/BusyIndi​​cator

Look at this WPF toolkit with a busy indicator: https://github.com/xceedsoftware/wpftoolkit/wiki/BusyIndicator

相对绾红妆 2024-10-15 10:05:43

我通过简单地显示一个对话框(因此用户无法与其他任何内容交互,它将显示在顶部)来完成此操作,然后处理 Closing 事件(因为用户可以按 Alt-F4)以查看操作是否已完成,否则我会取消闭幕式活动:

myWaitWindow.ShowDialog(); // this can be borderless window with a spinny thing


void Window_Closing(object sender, CancelEventArgs e)
{
  if(this.myOperation.IsRunning)  // you would have to have some way to see when your operation has finished
    e.Cancel = true;
}

I do this by simply displaying a dialog (so the user cannot interact with anything else and it will be displayed on top) then handle the Closing event (as the user could press Alt-F4) to see if the operation has finished otherwise I cancel the closing event:

myWaitWindow.ShowDialog(); // this can be borderless window with a spinny thing


void Window_Closing(object sender, CancelEventArgs e)
{
  if(this.myOperation.IsRunning)  // you would have to have some way to see when your operation has finished
    e.Cancel = true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文