123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- 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.Navigation;
- using System.Windows.Shapes;
- namespace PDF_Office.CustomControl
- {
- /// <summary>
- /// 渐隐提示控件
- /// </summary>
- public partial class ToastControl : UserControl
- {
- /// <summary>
- /// 这种小型组件,主要为UI显示效果的,就不用VM来处理了
- /// </summary>
- public ToastControl()
- {
- InitializeComponent();
- }
- public CornerRadius CornerRadius
- {
- get { return (CornerRadius)GetValue(CornerRadiusProperty); }
- set { SetValue(CornerRadiusProperty, value); }
- }
- public static readonly DependencyProperty CornerRadiusProperty =
- DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ToastControl), new PropertyMetadata(null));
- public new Brush Background
- {
- get { return (Brush)GetValue(BackgroundProperty); }
- set { SetValue(BackgroundProperty, value); }
- }
- public static new readonly DependencyProperty BackgroundProperty =
- DependencyProperty.Register("Background", typeof(Brush), typeof(ToastControl), new PropertyMetadata(Brushes.White));
- public string StringContent
- {
- get { return (string)GetValue(StringContentProperty); }
- set { SetValue(StringContentProperty, value); }
- }
- public static readonly DependencyProperty StringContentProperty =
- DependencyProperty.Register("StringContent", typeof(string), typeof(ToastControl), new PropertyMetadata(""));
- public Duration Duration
- {
- get { return (Duration)GetValue(DurationProperty); }
- set { SetValue(DurationProperty, value); }
- }
- public static readonly DependencyProperty DurationProperty =
- DependencyProperty.Register("Duration", typeof(Duration), typeof(ToastControl), new PropertyMetadata(new Duration(TimeSpan.FromSeconds(0))));
- public TimeSpan BeginTime
- {
- get { return (TimeSpan)GetValue(BeginTimeProperty); }
- set { SetValue(BeginTimeProperty, value); }
- }
- public static readonly DependencyProperty BeginTimeProperty =
- DependencyProperty.Register("BeginTime", typeof(TimeSpan), typeof(ToastControl), new PropertyMetadata(TimeSpan.FromSeconds(0)));
- private void DoubleAnimation_Completed(object sender, EventArgs e)
- {
- this.Visibility = Visibility.Collapsed;
- this.Opacity = 1;
- }
- private void Toast_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if((bool)e.NewValue)
- {
- DoubleAnimation doubleAnimation = new DoubleAnimation();
- doubleAnimation.Completed += DoubleAnimation_Completed;
- doubleAnimation.From = 1;
- doubleAnimation.To = 0;
- doubleAnimation.BeginTime = BeginTime;
- doubleAnimation.Duration = Duration;
- this.BeginAnimation(UserControl.OpacityProperty, doubleAnimation);
- }
- }
- }
- }
|