/// <summary> /// 更新颜色 /// </summary> /// <param name="newColor">新的颜色</param> /// <param name="preciseColor">如果新的颜色是由一个精确的颜色得来的,则应传递精确颜色值,否则传递null</param> protected void UpdateColor(Color newColor, HsvColor? preciseColor) { if (updatingColor) return; updatingColor = true; HsvColor hsvColor = preciseColor.HasValue ? preciseColor.Value : HsvColor.FromArgb(newColor); lastPreciseColor = preciseColor; if (shadeCanvas != null) { if (preciseColor == null && hsvColor.S == 0 && hsvColor.V == 0) { Canvas.SetLeft(shadeSelector, shadeCanvas.ActualWidth - shadeSelector.ActualWidth / 2); } else { Canvas.SetLeft(shadeSelector, hsvColor.S * shadeCanvas.ActualWidth - shadeSelector.ActualWidth / 2); } Canvas.SetTop(shadeSelector, (1 - hsvColor.V) * shadeCanvas.ActualHeight - shadeSelector.ActualHeight / 2); if (hsvColor.S > 0) { spectrumSlider.Value = hsvColor.H; } } if (Color == newColor) { Color = newColor; ForceUpdateTextBox(); } else { Color = newColor; } updatingColor = false; }