本文介绍了如何在 wpf 屏幕上显示忙消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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 have done this with a few programs. Here it is in a nutshell:

(这对于 MVVM 来说是最简单的.我已经很久没有使用 codebehid 来处理这样的事情了,我真的不能说是否有好的方法可以做到.)

(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. 在主窗口上创建边框.我通常将其设为黑色,透明度为 50%.给它加一个网格,把你想要的东西放进去,告诉用户它很忙.调整边框及其内部控件的大小以填充屏幕.
  2. 在您的主 ViewModel 上为 IsBusy 创建一个属性为布尔值.将其初始化为 False.将 Busy Border 的 Visibility 属性绑定到该属性.
  3. 接下来,为 Busy(Boolean) 到 Visibility 创建一个转换器类.将逻辑写入其中,以便当 value 为 True 时,可见性为 Visible,当 value 为 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>

这篇关于如何在 wpf 屏幕上显示忙消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:21