From 03baa03e0f96d1c4081673aae22be0809534badc Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Tue, 7 May 2024 20:07:49 +0530 Subject: [PATCH 1/2] Adding CopyToClipboard functionality in Colors page --- .../WPFGallery/Controls/ColorTile.xaml | 3 ++- .../WPFGallery/Controls/ColorTile.xaml.cs | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sample Applications/WPFGallery/Controls/ColorTile.xaml b/Sample Applications/WPFGallery/Controls/ColorTile.xaml index a762c9412..2db808442 100644 --- a/Sample Applications/WPFGallery/Controls/ColorTile.xaml +++ b/Sample Applications/WPFGallery/Controls/ColorTile.xaml @@ -50,9 +50,10 @@ Margin="0,12,12,0" HorizontalAlignment="Right" VerticalAlignment="Top" - Background="Transparent" BorderBrush="Transparent" Foreground="{TemplateBinding Foreground}" + Command="ApplicationCommands.Copy" + FocusManager.IsFocusScope="True" ToolTipService.ToolTip="Copy brush name"> diff --git a/Sample Applications/WPFGallery/Controls/ColorTile.xaml.cs b/Sample Applications/WPFGallery/Controls/ColorTile.xaml.cs index 87674bff1..768911ccd 100644 --- a/Sample Applications/WPFGallery/Controls/ColorTile.xaml.cs +++ b/Sample Applications/WPFGallery/Controls/ColorTile.xaml.cs @@ -20,6 +20,11 @@ namespace WPFGallery.Controls /// public partial class ColorTile : UserControl { + static ColorTile() + { + CommandManager.RegisterClassCommandBinding(typeof(ColorTile), new CommandBinding(ApplicationCommands.Copy, Copy_ColorBrushName)); + } + public CornerRadius TileRadius { get { return (CornerRadius)GetValue(TileRadiusProperty); } @@ -81,6 +86,23 @@ public bool ShowWarning // Using a DependencyProperty as the backing store for ShowSeparator. This enables animation, styling, binding, etc... public static readonly DependencyProperty ShowWarningProperty = DependencyProperty.Register("ShowWarning", typeof(bool), typeof(ColorTile), new PropertyMetadata(false)); - + + private static void Copy_ColorBrushName(object sender, RoutedEventArgs e) + { + if(sender is ColorTile colorTile) + { + if(!string.IsNullOrEmpty(colorTile.ColorBrushName)) + { + try + { + Clipboard.SetText(colorTile.ColorBrushName); + } + catch (Exception ex) + { + MessageBox.Show("Error copying to clipboard: " + ex.Message); + } + } + } + } } } From 4322e4b635f801932cd09ba9905bc11ade1a54b0 Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Tue, 7 May 2024 20:11:56 +0530 Subject: [PATCH 2/2] Fixing copy button background --- Sample Applications/WPFGallery/Controls/ColorTile.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Sample Applications/WPFGallery/Controls/ColorTile.xaml b/Sample Applications/WPFGallery/Controls/ColorTile.xaml index 2db808442..cb069853d 100644 --- a/Sample Applications/WPFGallery/Controls/ColorTile.xaml +++ b/Sample Applications/WPFGallery/Controls/ColorTile.xaml @@ -50,6 +50,7 @@ Margin="0,12,12,0" HorizontalAlignment="Right" VerticalAlignment="Top" + Background="Transparent" BorderBrush="Transparent" Foreground="{TemplateBinding Foreground}" Command="ApplicationCommands.Copy"