You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.8 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using CommonFunc.Tools;
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;
namespace CommonFunc
{
/// <summary>
/// HMessageBox.xaml 的交互逻辑
/// </summary>
public partial class HMessageBox : Window
{
#region 变量
/// <summary>
/// 显示的内容
/// </summary>
public string MessageBoxText { get; set; }
/// <summary>
/// 显示的图片
/// </summary>
public string ImagePath { get; set; }
/// <summary>
/// 控制显示 OK 按钮
/// </summary>
public Visibility OkButtonVisibility { get; set; }
/// <summary>
/// 控制显示 Cacncel 按钮
/// </summary>
public Visibility CancelButtonVisibility { get; set; }
/// <summary>
/// 控制显示 Yes 按钮
/// </summary>
public Visibility YesButtonVisibility { get; set; }
/// <summary>
/// 控制显示 No 按钮
/// </summary>
public Visibility NoButtonVisibility { get; set; }
/// <summary>
/// 消息框的返回值
/// </summary>
public CustomMessageBoxResult Result { get; set; }
#endregion
public HMessageBox()
{
InitializeComponent();
}
public void SetControl()
{
OkButton.Visibility = OkButtonVisibility;
YesButton.Visibility = YesButtonVisibility;
NoButton.Visibility = NoButtonVisibility;
CancelButton.Visibility = CancelButtonVisibility;
TxtMsg.Text = MessageBoxText;
if (!string.IsNullOrEmpty(ImagePath))
{
MsgImg.Source = new BitmapImage(new Uri(ImagePath, UriKind.RelativeOrAbsolute));
}
}
private void Window_Closed(object sender, EventArgs e)
{
this.Close();
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
Result = CustomMessageBoxResult.OK;
this.Close();
}
private void YesButton_Click(object sender, RoutedEventArgs e)
{
Result = CustomMessageBoxResult.Yes;
this.Close();
}
private void NoButton_Click(object sender, RoutedEventArgs e)
{
Result = CustomMessageBoxResult.No;
this.Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
Result = CustomMessageBoxResult.Cancel;
this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//while (true)
//{
// // 创建一个Storyboard对象
// Storyboard storyboard = new Storyboard();
// // 创建一个DoubleAnimation对象设置动画的起始值和结束值
// DoubleAnimation animation = new DoubleAnimation();
// animation.From = 0.0; // 完全显示
// animation.To = 1.0; // 完全隐藏
// animation.Duration = new Duration(TimeSpan.FromSeconds(1)); // 动画的持续时间
// // 将DoubleAnimation对象添加到Storyboard中并指定要动画的属性
// Storyboard.SetTarget(animation, MsgImg);
// Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));
// // 将动画添加到Storyboard中
// storyboard.Children.Add(animation);
// // 启动动画
// storyboard.Begin();
// // 创建一个Storyboard对象
// Storyboard storyboard1 = new Storyboard();
// // 创建一个DoubleAnimation对象设置动画的起始值和结束值
// DoubleAnimation animation1 = new DoubleAnimation();
// animation1.From = 1.0; // 完全显示
// animation1.To = 0.0; // 完全隐藏
// animation1.Duration = new Duration(TimeSpan.FromSeconds(1)); // 动画的持续时间
// // 将DoubleAnimation对象添加到Storyboard中并指定要动画的属性
// Storyboard.SetTarget(animation1, MsgImg);
// Storyboard.SetTargetProperty(animation1, new PropertyPath("Opacity"));
// // 将动画添加到Storyboard中
// storyboard1.Children.Add(animation1);
// // 启动动画
// storyboard1.Begin();
//}
}
}
}