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 { /// /// HMessageBox.xaml 的交互逻辑 /// public partial class HMessageBox : Window { #region 变量 /// /// 显示的内容 /// public string MessageBoxText { get; set; } /// /// 显示的图片 /// public string ImagePath { get; set; } /// /// 控制显示 OK 按钮 /// public Visibility OkButtonVisibility { get; set; } /// /// 控制显示 Cacncel 按钮 /// public Visibility CancelButtonVisibility { get; set; } /// /// 控制显示 Yes 按钮 /// public Visibility YesButtonVisibility { get; set; } /// /// 控制显示 No 按钮 /// public Visibility NoButtonVisibility { get; set; } /// /// 消息框的返回值 /// 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(); //} } } }