Files
29WxOrder/29WxOrderWpf/BaseWindows/BaseMsgWindow.xaml.cs
T

138 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Work.BaseForms;
namespace _29WxOrderWpf.BaseWindows
{
/// <summary>
/// BaseMsgWindow.xaml 的交互逻辑
/// </summary>
public partial class BaseMsgWindow : BaseWindow
{
public BaseMsgWindow()
{
InitializeComponent();
this.DataContext = this;
}
private static BaseMsgWindow CreateMsgForm(string msg, string caption, MsgWindowLevel wl)
{
BaseMsgWindow msgBox = new BaseMsgWindow { lblTitle = { Content = caption }, tbkMsg = { Text = msg } };
if (wl.Equals(MsgWindowLevel.LARGE))
{
msgBox.Width = (int)MsgWindowLevel.LARGE;
msgBox.Height = 500;
}
msgBox.btnOk.Margin = new Thickness(msgBox.btnCancel.Margin.Left, msgBox.btnCancel.Margin.Top, msgBox.btnCancel.Margin.Right, msgBox.btnCancel.Margin.Bottom); // 把确认按钮移到取消按钮上面
msgBox.btnCancel.Visibility = Visibility.Collapsed;
return msgBox;
}
public static BaseMsgWindow ShowInfo(string msg, string caption = "", Window window = null, MsgWindowLevel wl = MsgWindowLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "系统提示" : caption;
BaseMsgWindow msgBox = CreateMsgForm(msg, title, wl);
msgBox.imgTip.Source = Application.Current.Resources["imgBaseMsgInfo"] as ImageSource;
if (window != null)
msgBox.Owner = window;
else msgBox.Owner = MainWindow.Instance;
msgBox.ShowDialog();
return msgBox;
}
public static BaseMsgWindow ShowError(string msg, string caption = "", Window window = null, MsgWindowLevel wl = MsgWindowLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "系统错误" : caption;
BaseMsgWindow msgBox = CreateMsgForm(msg, title, wl);
msgBox.imgTip.Source = Application.Current.Resources["imgBaseMsgErr"] as ImageSource;
if (window != null)
msgBox.Owner = window;
else
msgBox.Owner = MainWindow.Instance;
msgBox.ShowDialog();
return msgBox;
}
public static BaseMsgWindow ShowConfirm(string msg, string caption = "", Window window = null, MsgWindowLevel fl = MsgWindowLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "确认系统提示" : caption;
BaseMsgWindow msgBox = new BaseMsgWindow
{
lblTitle = { Content = title },
tbkMsg = { Text = msg },
imgTip = { Source = Application.Current.Resources["imgBaseMsgQue"] as ImageSource },
};
if (fl.Equals(MsgWindowLevel.LARGE))
{
msgBox.Width = (int)MsgWindowLevel.LARGE;
msgBox.Height = 500;
}
if (window != null)
msgBox.Owner = window;
else
msgBox.Owner = MainWindow.Instance;
msgBox.ShowDialog();
return msgBox;
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
public static void ShowAnimateMessage(string message)
{
MainWindow.Instance.tbMessage.Text = message;
MainWindow.Instance.borderMessage.Visibility = Visibility.Visible;
// 创建Storyboard并添加动画
Storyboard storyboard = new Storyboard();
DoubleAnimation fadeInAnimation1 = new DoubleAnimation
{
From = 0, // 开始时完全透明
To = 1, // 结束时完全不透明
Duration = new Duration(TimeSpan.FromSeconds(0.2)) // 持续时间2秒
};
Storyboard.SetTarget(fadeInAnimation1, MainWindow.Instance.borderMessage);
Storyboard.SetTargetProperty(fadeInAnimation1, new PropertyPath(OpacityProperty));
storyboard.Children.Add(fadeInAnimation1);
DoubleAnimation fadeInAnimation2 = new DoubleAnimation
{
BeginTime = new TimeSpan(0, 0, 1),
From = 1,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(0.2)) // 持续时间2秒
};
Storyboard.SetTarget(fadeInAnimation2, MainWindow.Instance.borderMessage);
Storyboard.SetTargetProperty(fadeInAnimation2, new PropertyPath(OpacityProperty));
storyboard.Children.Add(fadeInAnimation2);
// 开始动画
storyboard.Begin();
}
}
public enum MsgWindowLevel
{
SMALL,
MEDIUM,
LARGE = 500
}
}