From a3ce84952adec793a8086310731a218d2aa1faeb Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Wed, 21 Sep 2011 22:34:33 +0000 Subject: [PATCH] ColorPicker: fixed null exception when trying to re-template in Blend --- .../ColorPicker/Implementation/ColorPicker.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Implementation/ColorPicker.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Implementation/ColorPicker.cs index a6d0f3f6..ba0f4c49 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Implementation/ColorPicker.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/Implementation/ColorPicker.cs @@ -13,7 +13,6 @@ namespace Microsoft.Windows.Controls { #region Members - private Popup _colorPickerCanvasPopup; private ListBox _availableColors; private ListBox _standardColors; private ListBox _recentColors; @@ -227,28 +226,32 @@ namespace Microsoft.Windows.Controls { base.OnApplyTemplate(); - _colorPickerCanvasPopup = (Popup)GetTemplateChild("PART_ColorPickerPalettePopup"); - //_colorPickerCanvasPopup.Opened += ColorPickerCanvasPopup_Opened; + if (_availableColors != null) + _availableColors.SelectionChanged -= Color_SelectionChanged; _availableColors = (ListBox)GetTemplateChild("PART_AvailableColors"); - _availableColors.SelectionChanged += Color_SelectionChanged; + if (_availableColors != null) + _availableColors.SelectionChanged += Color_SelectionChanged; + + if (_standardColors != null) + _standardColors.SelectionChanged -= Color_SelectionChanged; _standardColors = (ListBox)GetTemplateChild("PART_StandardColors"); - _standardColors.SelectionChanged += Color_SelectionChanged; + if (_standardColors != null) + _standardColors.SelectionChanged += Color_SelectionChanged; + + if (_recentColors != null) + _recentColors.SelectionChanged -= Color_SelectionChanged; _recentColors = (ListBox)GetTemplateChild("PART_RecentColors"); - _recentColors.SelectionChanged += Color_SelectionChanged; + if (_recentColors != null) + _recentColors.SelectionChanged += Color_SelectionChanged; } #endregion //Base Class Overrides #region Event Handlers - void ColorPickerCanvasPopup_Opened(object sender, EventArgs e) - { - - } - private void OnKeyDown(object sender, KeyEventArgs e) { switch (e.Key)