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
1216

被折叠的 条评论
为什么被折叠?



