Ver código fonte

组件-补充Toast提示控件

ZhouJieSheng 2 anos atrás
pai
commit
f934ad7627

+ 32 - 0
PDF Office/CustomControl/ToastControl.xaml

@@ -0,0 +1,32 @@
+<UserControl
+    x:Class="PDF_Office.CustomControl.ToastControl"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:PDF_Office.CustomControl"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    Name="Toast"
+    Width="auto"
+    Height="auto"
+    d:DesignHeight="450"
+    d:DesignWidth="800"
+    Background="Transparent"
+    IsVisibleChanged="Toast_IsVisibleChanged"
+    Visibility="Collapsed"
+    mc:Ignorable="d">
+    <Border
+        Name="tipBorder"
+        HorizontalAlignment="Center"
+        Background="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=Background}"
+        CornerRadius="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=CornerRadius}"
+        Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=Visibility}">
+        <TextBlock
+            Name="txtTip"
+            Padding="6,2,6,2"
+            HorizontalAlignment="Center"
+            Background="Transparent"
+            FontSize="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=FontSize}"
+            Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=Foreground}"
+            Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ToastControl}, Path=StringContent}" />
+    </Border>
+</UserControl>

+ 102 - 0
PDF Office/CustomControl/ToastControl.xaml.cs

@@ -0,0 +1,102 @@
+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;
+        }
+
+        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);
+            }
+        }
+    }
+}

+ 14 - 1
PDF Office/ViewModels/Dialog/FullScreenWindowViewModel.cs

@@ -9,6 +9,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels.Dialog
@@ -17,6 +18,17 @@ namespace PDF_Office.ViewModels.Dialog
     {
         public string Title => "";
 
+        private Visibility showTip = Visibility.Collapsed;
+
+        public Visibility ShowTip
+        {
+            get { return showTip; }
+            set
+            {
+                SetProperty(ref showTip, value);
+            }
+        }
+
         private CPDFViewer PDFViewer;
         public DelegateCommand ExitCommand { get; set; }
 
@@ -48,7 +60,8 @@ namespace PDF_Office.ViewModels.Dialog
             var Grid = grid as Grid;
             if(Grid!=null&&PDFViewer!=null)
             {
-                Grid.Children.Insert(0,PDFViewer);
+                    Grid.Children.Insert(0, PDFViewer);
+                    ShowTip = Visibility.Visible;
             }
         }
 

+ 14 - 0
PDF Office/Views/Dialog/FullScreenWindow.xaml

@@ -2,6 +2,7 @@
     x:Class="PDF_Office.Views.Dialog.FullScreenWindow"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:cus="clr-namespace:PDF_Office.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:dialog="clr-namespace:PDF_Office.ViewModels.Dialog"
     xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
@@ -84,6 +85,19 @@
                 </EventTrigger>
             </Grid.Triggers>
         </Grid>
+        <cus:ToastControl
+            Width="auto"
+            Height="auto"
+            Margin="0,0,0,300"
+            VerticalAlignment="Bottom"
+            Background="#89000000"
+            BeginTime="0:0:0:3"
+            CornerRadius="4"
+            FontSize="14"
+            Foreground="White"
+            StringContent="Press Esc To Exit Full Mode"
+            Visibility="{Binding ShowTip}"
+            Duration="0:0:0:3" />
         <i:Interaction.Triggers>
             <i:EventTrigger EventName="Loaded">
                 <i:InvokeCommandAction Command="{Binding LoadCommand}" CommandParameter="{Binding ElementName=GridRoot}" />