`

全局等待提示框

阅读更多

xmal代码(Loading.xaml):

<UserControl x:Class="Longshine.SLLib.CommonXaml.Loading"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    >
    <Grid x:Name="LayoutRoot" Width="Auto" Height="Auto">
        <Grid Background="Black" Opacity="0.2"></Grid>
        <Canvas Width="320" Height="50">
            <Rectangle RadiusX="8" RadiusY="8" Stroke="{x:Null}" Fill="#19000000" Height="49" Width="316" Canvas.Left="6" Canvas.Top="3"/>
            <Rectangle RadiusX="8" RadiusY="8" Stroke="{x:Null}" Fill="#19000000" Height="48" Width="316" Canvas.Left="5" Canvas.Top="3"/>
            <Border Height="50" Width="320" Background="#FFFFFFFF" BorderBrush="#FFACACAC" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8">
                <Rectangle RadiusX="8" RadiusY="8" Stroke="{x:Null}" Margin="1,1,1,1">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFFFFFFF"/>
                            <GradientStop Color="#FFE9E9E9" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Border>
        </Canvas>
        <Grid Width="320" Height="50" VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="5*" />
                <ColumnDefinition Width="10*" />
                <ColumnDefinition Width="80*" />
                <ColumnDefinition Width="5*" />
            </Grid.ColumnDefinitions>
            <Image Stretch="None" Source="Images/loading.png" Grid.Column="1" Opacity="0.3" />
            <Image x:Name="loadingImage" Stretch="None" Source="Images/loading.png" Grid.Column="1" RenderTransformOrigin="0.5,0.5">
                <Image.RenderTransform>
                    <RotateTransform Angle="0"></RotateTransform>
                </Image.RenderTransform>
            </Image>
            <TextBlock x:Name="titleText" FontFamily="Calibri" FontSize="13" Foreground="#FF000000" HorizontalAlignment="Left" Grid.Column="3"/>
            <TextBlock Text="系统处理:" x:Name="loadingText"
    			FontFamily="Verdana" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="2"/>
        </Grid>
    </Grid>
    <UserControl.Resources>
        <Storyboard x:Name="storyboard">
            <DoubleAnimation Storyboard.TargetName="loadingImage"  Duration="0:0:0.7" To="360" Storyboard.TargetProperty="(UIElement.RenderTransform).RotateTransform.Angle" RepeatBehavior="Forever"></DoubleAnimation>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="loadingText" Storyboard.TargetProperty="Opacity" RepeatBehavior="Forever">
                <SplineDoubleKeyFrame KeyTime="00:00:0.0" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:0.5" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:1.0" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
</UserControl>

 CS代码(Loading.xaml.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Longshine.SLLib.CommonXaml
{
    public partial class Loading : UserControl
    {
        public string Title
        {
            get { return this.titleText.Text; }
            set { this.titleText.Text = value; }
        }

        public Loading()
        {
            InitializeComponent();
            this.storyboard.Begin();
        }

        public void SetLoadingText(string text)
        {
            this.loadingText.Text = "系统处理: " + text;
        }
    }
}

应用代码(LSWindow.cs):

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Longshine.SLLib.CommonXaml;
using System.Collections.Generic;
using Longshine.SLLib.InputControls;
using System.Threading;
using System.Windows.Threading;
using Telerik.Windows.Controls;
using ClientUtils;

namespace Longshine.SLLib
{
    public class LSWindow
    {
        private static Loading loading;

        static LSWindow()
        {
            System.Windows.Controls.Control rootPage = Application.Current.RootVisual as System.Windows.Controls.Control;
            Panel panel = VisualTreeHelper.GetChild(rootPage, 0) as Panel;
            int count = VisualTreeHelper.GetChildrenCount(rootPage);
            if (loading == null)
            {
                loading = new Loading();
                loading.Visibility = Visibility.Collapsed;
                panel.Children.Add(loading);
            }

        }

        public static void ShowLoading(string message)
        {
            if (loading != null)
            {
                loading.Dispatcher.BeginInvoke(() =>
                {
                    loading.Visibility = Visibility.Visible;
                    loading.SetLoadingText(message);
                });
            }
        }

        public static void HideLoading()
        {
            if (loading != null)
                loading.Dispatcher.BeginInvoke(() => loading.Visibility = Visibility.Collapsed);
        }


        /// <summary>
        /// 记录大批量信息,提示用户
        /// </summary>
        /// <param name="msg"></param>
        public static void MessagePrompt(List<string> msg)
        {
            var msgPromptForm = new MessagePromptForm();
            msgPromptForm.lbMessage.ItemsSource = msg;
            msgPromptForm.Show();
        }

        /// <summary>
        /// 一般性弹出提示框
        /// </summary>
        /// <param name="msg"></param>
        public static void Alert(object msg)
        {
            RadWindow.Alert(new TextBlock { Text = msg.ToString(), Width = 300, TextWrapping = TextWrapping.Wrap });
        }

        /// <summary>
        /// 捕获异常信息,提示用户,并记录日志
        /// </summary>
        /// <param name="ex">异常</param>
        public static void AlertError(System.Exception ex)
        {
            AlertError(ex, true);
        }
        /// <summary>
        /// 捕获异常信息,提示用户,是否记录日志
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="isLog">是否记录日志</param>
        public static void AlertError(System.Exception ex, bool isLog)
        {
            if (ex == null) return;
            RadWindow.Alert(new TextBlock { Text = "出现异常:" + ex.Message + "\n可能原因:" + ex.StackTrace, Width = 300, TextWrapping = TextWrapping.Wrap });
            if(isLog)
                LogFactory.FileLogger.Log("出现异常:" + ex.Message + ", 可能原因:" + ex.StackTrace, LOGLEVEL.FATAL);
        }

    }
}

界面:

 

注明:全局等待提示框代码来自于EasySL

 

  • 大小: 3.8 KB
分享到:
评论

相关推荐

    QT中进度条对话框等待耗时操作

    考虑程序的友好性,当程序在执行一项耗时操作时,界面应告诉用户“程序还在运行中”,那么,QT中进度对话框(QProgressDialog)可以满足要求

    易语言 茶凉专用模块

    参数 等待时间, 整数型 .子程序 超级延时, , 公开, 高精度延时,cpu占用低,窗口不卡死,一次最大可延时几年 (无返回值) .参数 延时间隔, 整数型, , 1000微秒 = 1毫秒 ; 1000毫秒 = 1秒 .参数 延时单位, 整数型, 可空...

    java微信公众号MVC开发框架

    WeixinConfigurer是微信上下文全局配置类,里面包含了处理微信类扫描、微信消息重排处理、微信方法执行线程池大小、微信方法调用超时阀值等方面的配置,packages包扫描配置是唯一必须的配置部分,这个配置在快速入门...

    Windows编程循序渐进.part2

    1.2.3 对话框类 6 1.2.4 添加消息响应 7 第2章 对话框应用程序 9 2.1 模态对话框 9 2.1.1 实例:使用MFC实现模态对话框 9 2.1.2 实例:使用Win32 API实现模态对话框 10 2.2 非模态对话框 12 2.2.1 实例:...

    Windows编程循序渐进.part3

    1.2.3 对话框类 6 1.2.4 添加消息响应 7 第2章 对话框应用程序 9 2.1 模态对话框 9 2.1.1 实例:使用MFC实现模态对话框 9 2.1.2 实例:使用Win32 API实现模态对话框 10 2.2 非模态对话框 12 2.2.1 实例:...

    计件工资_源码_VB6.0

    工作量和工资的统计,包括个人的统计(工资条)和总体统计(统筹全局)。 四. 提供形象化的图表来显示统计结果,为您更加直观的决策提供依据。 另外在的主界面上我们为您提供10幅精心挑选的背景画面来适应不同的...

    VC++ 专家指导.doc

    (79) 我需要在我的程序中设置全局变量,以使文档中的所有类都能访问。我应该吧它放到哪儿? 68 (80) 我听说MFC可以发现内存漏洞,我怎样使用该特性? 68 (81) 我怎样才能在我的应用程序中循环浏览已经打开的文档...

    易语言程序免安装版下载

    修改扩展界面支持库一,为“树形框”增加多态检查框功能,相应地添加了多个与检查框相关的属性、方法和事件。 17. 修改高级表格支持库,允许“复制选定文本()”“剪切选定文本()”在“允许选择块”属性为假时复制...

    《程序天下:JavaScript实例自学手册》光盘源码

    12.10 打开窗口的等待提示 12.11 在打开的窗口中返回数据 12.12 创建弹出窗口 12.13 不允许窗口出现滚动条 12.14 页面打开的同时打开另外两个窗口 12.15 慢慢变大的窗口 12.16 设置新打开的窗口为活动窗口 12.17 ...

    程序天下:JavaScript实例自学手册

    12.10 打开窗口的等待提示 12.11 在打开的窗口中返回数据 12.12 创建弹出窗口 12.13 不允许窗口出现滚动条 12.14 页面打开的同时打开另外两个窗口 12.15 慢慢变大的窗口 12.16 设置新打开的窗口为活动窗口 12.17 ...

    Dialogic从入门到系统工程师_完整版

    11.4.1 改变录音提示音长度 264 11.4.2 速度和音量控制 264 11.4.3 事务录音 264 11.4.4 WAVE文件偏移量放音 268 11.4.5 压缩式录音 268 11.4.6 回声消除资源 269 11.4.7 GSM和G.726语音编码 269 11.5 来电...

    jira用户操作指南(详细版)

    3. 饼图小工具已经出现在面板中,并等待你继续配置: 1. '项目或保存的过滤器' — 输入项目或过滤器的名称,或点击'高级搜索'链接搜索项目或已经保存的过滤器。 2. '统计类型' — 选择饼图按照哪个字段进行分组统计...

    Visual C++编程技巧精选500例.pdf

    第1章 消息框 001 如何创建消息框? 002 如何设置消息框标题? 003 如何使用资源串创建消息框? 004 如何使用资源串动态显示消息框内容? 005 如何使消息框显示问号图标? 006 如何使消息框显示“是/否”按钮? 007 如何...

    JavaScript笔记

    JavaScript:定义行为和动作 (基于对象和事件驱动的客户端脚本语言;也是一种广泛应用于客户端Web开发的脚本语言) 基于对象:网页中的一切...22.全局函数:不用任何对象点(.)就可以调用--可用于所有的 JavaScript ...

    进销存管理软件源码-易语言

    9:加入全局进度条和状态条文本提示! 10:修复已发现的各种小bug,使得程序更加安全。 11:加快添加报单写入的速度 12:修复有时候子操作框占用屏幕的BUG 13:优化程序操作和显示速度 8-20 1:增加帐号列表显示 2:...

Global site tag (gtag.js) - Google Analytics