diff --git a/Ink Canvas/App.xaml b/Ink Canvas/App.xaml index 3d4723fd..5ce16684 100644 --- a/Ink Canvas/App.xaml +++ b/Ink Canvas/App.xaml @@ -262,7 +262,7 @@ ToolTipText="InkCanvasForClass" ContextMenu="{StaticResource SysTrayMenu}" IconSource="/Resources/icc.ico"/> - + diff --git a/Ink Canvas/Controls/CopyButton.xaml b/Ink Canvas/Controls/CopyButton.xaml new file mode 100644 index 00000000..fe3bff2e --- /dev/null +++ b/Ink Canvas/Controls/CopyButton.xaml @@ -0,0 +1,24 @@ + + + diff --git a/Ink Canvas/Controls/CopyButton.xaml.cs b/Ink Canvas/Controls/CopyButton.xaml.cs new file mode 100644 index 00000000..fc2c2f30 --- /dev/null +++ b/Ink Canvas/Controls/CopyButton.xaml.cs @@ -0,0 +1,115 @@ +using System; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Animation; + +namespace Ink_Canvas.Controls +{ + public partial class CopyButton : UserControl + { + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + nameof(Text), typeof(string), typeof(CopyButton), new PropertyMetadata(string.Empty)); + + public string Text + { + get => (string)GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public event EventHandler Click; + + public CopyButton() + { + InitializeComponent(); + } + + private void CopyButton_Click(object sender, RoutedEventArgs e) + { + try + { + if (!string.IsNullOrEmpty(Text)) + { + Clipboard.SetText(Text); + } + + ShowSuccessAnimation(); + Click?.Invoke(this, EventArgs.Empty); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString(), "Unable to Perform Copy", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private async void ShowSuccessAnimation() + { + var copyScaleAnim = new DoubleAnimation + { + To = 0, + Duration = TimeSpan.FromMilliseconds(150) + }; + ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim); + + var copyOpacityAnim = new DoubleAnimation + { + To = 0, + BeginTime = TimeSpan.FromMilliseconds(100), + Duration = TimeSpan.FromMilliseconds(10) + }; + FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim); + + await Task.Delay(150); + var successScaleAnim = new DoubleAnimation + { + To = 1, + Duration = TimeSpan.FromMilliseconds(150), + EasingFunction = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.2 } + }; + ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim); + + var successOpacityAnim = new DoubleAnimation + { + To = 1, + Duration = TimeSpan.FromMilliseconds(15) + }; + FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim); + + await Task.Delay(1000); + ShowCopyAnimation(); + } + + private async void ShowCopyAnimation() + { + var successOpacityAnim = new DoubleAnimation + { + To = 0, + Duration = TimeSpan.FromMilliseconds(150) + }; + FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim); + + await Task.Delay(150); + var copyScaleAnim = new DoubleAnimation + { + To = 1, + Duration = TimeSpan.Zero + }; + ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim); + + var copyOpacityAnim = new DoubleAnimation + { + To = 1, + Duration = TimeSpan.FromMilliseconds(150) + }; + FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim); + + var successScaleAnim = new DoubleAnimation + { + To = 0, + Duration = TimeSpan.Zero + }; + ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim); + } + } +} diff --git a/Ink Canvas/Helpers/PPTManager.cs b/Ink Canvas/Helpers/PPTManager.cs index 86922667..a02c3371 100644 --- a/Ink Canvas/Helpers/PPTManager.cs +++ b/Ink Canvas/Helpers/PPTManager.cs @@ -390,11 +390,15 @@ private void DisconnectFromPPT() { try { - PPTApplication.PresentationOpen -= OnPresentationOpen; - PPTApplication.PresentationClose -= OnPresentationClose; - PPTApplication.SlideShowBegin -= OnSlideShowBegin; - PPTApplication.SlideShowNextSlide -= OnSlideShowNextSlide; - PPTApplication.SlideShowEnd -= OnSlideShowEnd; + // 再次检查PPTApplication是否为null,因为可能在异步操作期间被修改 + if (PPTApplication != null && Marshal.IsComObject(PPTApplication)) + { + PPTApplication.PresentationOpen -= OnPresentationOpen; + PPTApplication.PresentationClose -= OnPresentationClose; + PPTApplication.SlideShowBegin -= OnSlideShowBegin; + PPTApplication.SlideShowNextSlide -= OnSlideShowNextSlide; + PPTApplication.SlideShowEnd -= OnSlideShowEnd; + } } catch (COMException comEx) { diff --git a/Ink Canvas/InkCanvasForClass.csproj b/Ink Canvas/InkCanvasForClass.csproj index 969d8176..8ce91b1b 100644 --- a/Ink Canvas/InkCanvasForClass.csproj +++ b/Ink Canvas/InkCanvasForClass.csproj @@ -114,6 +114,7 @@ + @@ -563,14 +564,7 @@ - - - - - - Ink_Canvas.Properties.Strings.enUS.xml - - + diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 070af88d..71d20269 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -643,15 +643,15 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -