//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- /// <summary> /// When overridden in a derived class, is invoked whenever application code or internal /// processes call <see cref="FrameworkElement.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { if (_slider != null) { _slider.ValueChanged -= OnSliderChanged; _slider = null; } if (_int32ValueControl != null) { _int32ValueControl.ValueChanged -= OnInt32ValueChanged; _int32ValueControl = null; } if (_doubleValueControl != null) { _doubleValueControl.ValueChanged -= OnDoubleValueChanged; _doubleValueControl = null; } base.OnApplyTemplate(); _slider = GetTemplateChild("PART_Slider") as ColorSlider1D; if (_slider != null) { _slider.ValueChanged += OnSliderChanged; } _int32ValueControl = GetTemplateChild("PART_Int32Value") as NumericUpDown; if (_int32ValueControl != null) { _int32ValueControl.ValueChanged += OnInt32ValueChanged; } _doubleValueControl = GetTemplateChild("PART_DoubleValue") as NumericUpDown; if (_doubleValueControl != null) { _doubleValueControl.ValueChanged += OnDoubleValueChanged; } }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal /// processes call <see cref="FrameworkElement.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { // Cleanup if (_eyeDropperButton != null) { _eyeDropperButton.Click += OnEyeDropperButtonClicked; _eyeDropperButton = null; } _oldColorNoAlphaShape = null; _oldColorShape = null; _newColorNoAlphaShape = null; _newColorShape = null; _hexValueTextBox = null; _slider1D = null; _slider2D = null; if (_buttonH != null) { _buttonH.Checked -= OnRadioButtonChecked; _buttonH = null; } if (_buttonS != null) { _buttonS.Checked -= OnRadioButtonChecked; _buttonS = null; } if (_buttonV != null) { _buttonV.Checked -= OnRadioButtonChecked; _buttonV = null; } if (_buttonR != null) { _buttonR.Checked -= OnRadioButtonChecked; _buttonR = null; } if (_buttonG != null) { _buttonG.Checked -= OnRadioButtonChecked; _buttonG = null; } if (_buttonB != null) { _buttonB.Checked -= OnRadioButtonChecked; _buttonB = null; } if (_colorSpaceSelector != null) { _colorSpaceSelector.SelectionChanged -= OnColorSpaceSelectionChanged; _colorSpaceSelector = null; } base.OnApplyTemplate(); // Get TemplateParts. // Store color component enums in tags of color component controls. // If a template part is missing, create an empty dummy element to avoid many NullReference checks. // Where necessary, add an event handler. _colorHControl = GetTemplateChild("PART_H") as ColorComponentControl ?? new ColorComponentControl(); _colorHControl.Tag = ColorComponents.Hue; _colorSControl = GetTemplateChild("PART_S") as ColorComponentControl ?? new ColorComponentControl(); _colorSControl.Tag = ColorComponents.Saturation; _colorVControl = GetTemplateChild("PART_V") as ColorComponentControl ?? new ColorComponentControl(); _colorVControl.Tag = ColorComponents.Value; _colorRControl = GetTemplateChild("PART_R") as ColorComponentControl ?? new ColorComponentControl(); _colorRControl.DisplayValueConverter = _colorSpaceConverter; _colorRControl.Tag = ColorComponents.Red; _colorGControl = GetTemplateChild("PART_G") as ColorComponentControl ?? new ColorComponentControl(); _colorGControl.DisplayValueConverter = _colorSpaceConverter; _colorGControl.Tag = ColorComponents.Green; _colorBControl = GetTemplateChild("PART_B") as ColorComponentControl ?? new ColorComponentControl(); _colorBControl.DisplayValueConverter = _colorSpaceConverter; _colorBControl.Tag = ColorComponents.Blue; _colorAControl = GetTemplateChild("PART_A") as ColorComponentControl ?? new ColorComponentControl(); _colorAControl.Tag = ColorComponents.Alpha; _eyeDropperButton = GetTemplateChild("PART_EyeDropperButton") as Button; if (_eyeDropperButton != null) _eyeDropperButton.Click += OnEyeDropperButtonClicked; _oldColorNoAlphaShape = GetTemplateChild("PART_OldColorNoAlpha") as Shape ?? new Rectangle(); _oldColorShape = GetTemplateChild("PART_OldColor") as Shape ?? new Rectangle(); _newColorNoAlphaShape = GetTemplateChild("PART_NewColorNoAlpha") as Shape ?? new Rectangle(); _newColorShape = GetTemplateChild("PART_NewColor") as Shape ?? new Rectangle(); _hexValueTextBox = GetTemplateChild("PART_HexValue") as TextBox ?? new TextBox(); _hexValueTextBox.Tag = ColorComponents.Red | ColorComponents.Green | ColorComponents.Blue | ColorComponents.Alpha; _slider1D = GetTemplateChild("PART_Slider1D") as ColorSlider1D ?? new ColorSlider1D(); _slider2D = GetTemplateChild("PART_Slider2D") as ColorSlider2D ?? new ColorSlider2D(); _slider2D.SizeChanged += OnDetailAreaSizeChanged; _buttonH = GetTemplateChild("PART_ButtonH") as RadioButton ?? new RadioButton(); _buttonH.Checked += OnRadioButtonChecked; _buttonS = GetTemplateChild("PART_ButtonS") as RadioButton ?? new RadioButton(); _buttonS.Checked += OnRadioButtonChecked; _buttonV = GetTemplateChild("PART_ButtonV") as RadioButton ?? new RadioButton(); _buttonV.Checked += OnRadioButtonChecked; _buttonR = GetTemplateChild("PART_ButtonR") as RadioButton ?? new RadioButton(); _buttonR.Checked += OnRadioButtonChecked; _buttonG = GetTemplateChild("PART_ButtonG") as RadioButton ?? new RadioButton(); _buttonG.Checked += OnRadioButtonChecked; _buttonB = GetTemplateChild("PART_ButtonB") as RadioButton ?? new RadioButton(); _buttonB.Checked += OnRadioButtonChecked; _colorSpaceSelector = GetTemplateChild("PART_ColorSpace") as Selector; if (_colorSpaceSelector != null) { _colorSpaceSelector.SelectedIndex = (int)ColorSpace; _colorSpaceSelector.SelectionChanged += OnColorSpaceSelectionChanged; } OnSelectedComponentChanged(this, new DependencyPropertyChangedEventArgs()); }
//-------------------------------------------------------------- /// <summary> /// When overridden in a derived class, is invoked whenever application code or internal /// processes call <see cref="FrameworkElement.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { if (_slider != null) { _slider.ValueChanged -= OnSliderChanged; _slider = null; } if (_int32ValueControl != null) { _int32ValueControl.ValueChanged -= OnInt32ValueChanged; _int32ValueControl = null; } if (_doubleValueControl != null) { _doubleValueControl.ValueChanged -= OnDoubleValueChanged; _doubleValueControl = null; } base.OnApplyTemplate(); _slider = GetTemplateChild("PART_Slider") as ColorSlider1D; if (_slider != null) _slider.ValueChanged += OnSliderChanged; _int32ValueControl = GetTemplateChild("PART_Int32Value") as NumericUpDown; if (_int32ValueControl != null) _int32ValueControl.ValueChanged += OnInt32ValueChanged; _doubleValueControl = GetTemplateChild("PART_DoubleValue") as NumericUpDown; if (_doubleValueControl != null) _doubleValueControl.ValueChanged += OnDoubleValueChanged; }