diff --git a/Sample Applications/WPFGallery/Controls/ColorTile.xaml b/Sample Applications/WPFGallery/Controls/ColorTile.xaml index a762c9412..cb069853d 100644 --- a/Sample Applications/WPFGallery/Controls/ColorTile.xaml +++ b/Sample Applications/WPFGallery/Controls/ColorTile.xaml @@ -53,6 +53,8 @@ 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); + } + } + } + } } }