From 17e1e9f05f96d64c65b5ae81cf15b311ce00f530 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Thu, 10 Feb 2011 01:10:45 +0000 Subject: [PATCH] ColorPicker: added new property that allows you to specify how to show the color information. You can show just the color or the color and color name. Just set the DisplayColorAndName property to true to display the color block and the name of the color next to it. --- .../ColorPicker/ColorPicker.cs | 45 +++++++++++-------- .../ColorPicker/ColorUtilities.cs | 8 ++-- .../WPFToolkit.Extended/Themes/Generic.xaml | 33 +++++++++++--- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs index 38f28c26..633c430a 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs @@ -13,11 +13,11 @@ namespace Microsoft.Windows.Controls { #region Members - //ToggleButton _colorPickerToggleButton; - Popup _colorPickerCanvasPopup; - ListBox _availableColors; - ListBox _standardColors; - ListBox _recentColors; + //private ToggleButton _colorPickerToggleButton; + private Popup _colorPickerCanvasPopup; + private ListBox _availableColors; + private ListBox _standardColors; + private ListBox _recentColors; #endregion //Members @@ -43,7 +43,18 @@ namespace Microsoft.Windows.Controls set { SetValue(ButtonStyleProperty, value); } } - #endregion //ButtonStyle + #endregion //ButtonStyle + + #region DisplayColorAndName + + public static readonly DependencyProperty DisplayColorAndNameProperty = DependencyProperty.Register("DisplayColorAndName", typeof(bool), typeof(ColorPicker), new UIPropertyMetadata(false)); + public bool DisplayColorAndName + { + get { return (bool)GetValue(DisplayColorAndNameProperty); } + set { SetValue(DisplayColorAndNameProperty, value); } + } + + #endregion //DisplayColorAndName #region IsOpen @@ -85,7 +96,7 @@ namespace Microsoft.Windows.Controls private void OnSelectedColorChanged(Color oldValue, Color newValue) { - //SelectedColorText = newValue.GetColorName(); + SelectedColorText = newValue.GetColorName(); RoutedPropertyChangedEventArgs args = new RoutedPropertyChangedEventArgs(oldValue, newValue); args.RoutedEvent = ColorPicker.SelectedColorChangedEvent; @@ -96,12 +107,12 @@ namespace Microsoft.Windows.Controls #region SelectedColorText - //public static readonly DependencyProperty SelectedColorTextProperty = DependencyProperty.Register("SelectedColorText", typeof(string), typeof(ColorPicker), new UIPropertyMetadata("Black")); - //public string SelectedColorText - //{ - // get { return (string)GetValue(SelectedColorTextProperty); } - // protected set { SetValue(SelectedColorTextProperty, value); } - //} + public static readonly DependencyProperty SelectedColorTextProperty = DependencyProperty.Register("SelectedColorText", typeof(string), typeof(ColorPicker), new UIPropertyMetadata("Black")); + public string SelectedColorText + { + get { return (string)GetValue(SelectedColorTextProperty); } + protected set { SetValue(SelectedColorTextProperty, value); } + } #endregion //SelectedColorText @@ -247,13 +258,11 @@ namespace Microsoft.Windows.Controls { ObservableCollection _standardColors = new ObservableCollection(); - PropertyInfo[] properties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public); - foreach (PropertyInfo info in properties) + foreach (var item in ColorUtilities.KnownColors) { - if (String.Compare(info.Name, "Transparent", false) != 0) + if (String.Compare(item.Key, "Transparent", false) != 0) { - Color c = (Color)info.GetValue(typeof(Colors), null); - var colorItem = new ColorItem(c, info.Name); + var colorItem = new ColorItem(item.Value, item.Key); if (!_standardColors.Contains(colorItem)) _standardColors.Add(colorItem); } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs index daed46ce..6076ad18 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs @@ -8,12 +8,14 @@ namespace Microsoft.Windows.Controls { static class ColorUtilities { + public static readonly Dictionary KnownColors = GetKnownColors(); + public static string GetColorName(this Color color) { - return _knownColors.Where(kvp => kvp.Value.Equals(color)).Select(kvp => kvp.Key).FirstOrDefault(); + return KnownColors.Where(kvp => kvp.Value.Equals(color)).Select(kvp => kvp.Key).FirstOrDefault(); } - static readonly Dictionary _knownColors = GetKnownColors(); - static Dictionary GetKnownColors() + + private static Dictionary GetKnownColors() { var colorProperties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public); return colorProperties.ToDictionary(p => p.Name, p => (Color)p.GetValue(null, null)); diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml index bb1612cf..9b8fe60d 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml @@ -645,7 +645,9 @@ + + @@ -689,7 +691,7 @@ - +