protected virtual void OnHexadecimalStringChanged(string oldValue, string newValue) { if (!SelectedColor.ToString().Equals(newValue)) { UpdateSelectedColor((Color)ColorConverter.ConvertFromString(newValue)); } }
private void OnMouseDownCommandEx(MouseButtonEventArgs args) { SelectedPath = args.OriginalSource as Path; if (SelectedPath != null) { PathViewModel path = SelectedPath.DataContext as PathViewModel; path.Fill = SelectedColor.ToString(); } }
private void CreateBackgroundColor() { var background = new BackgroundViewModel() { Type = BackgroundType.SolidColor, BackgroundData = SelectedColor.ToString() }; UserData.Backgrounds.Add(background); HideCreateView(); }
private void CalculateColor(Point p) { HsvColor hsv = new HsvColor(360 - _spectrumSlider.Value, 1, 1) { S = p.X, V = 1 - p.Y }; var currentColor = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V); currentColor.A = A; SelectedColor = currentColor; HexadecimalString = SelectedColor.ToString(); }
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { //Get the Selected Color SelectedColor = (Color)imgcanvas?.SelectedColor; //Convert Selected Color to string Hex = SelectedColor.ToString(); //Create an Html Hex Color HtmlHex = Hex.Replace("#FF", "#"); //Call the OnSelectedColor OnColorSelected?.Invoke(SelectedColor); base.OnPropertyChanged(e); }
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); //gets slider AlphaSlider = this.GetControl <Slider>(e, "PART_AlphaSlider"); HexTextBox = this.GetControl <TextBox>(e, "PART_HexTextBox"); ValueSaturationPicker = this.GetControl <HuePickerBase>(e, "PART_SaturationValuePicker"); HueSlider = this.GetControl <RadialColorSlider>(e, "PART_HueSlider"); SelectNewColor(PreviewColor, UpdatedColorReason.ColorPickerInitializated); RadialColorSlider.ValueProperty.Changed.AddClassHandler <RadialColorSlider>((x, e) => { if (e.Sender == HueSlider) { SelectNewColor(new HSV(HueSlider.Value, S, V).ToColor(), UpdatedColorReason.HueChanged); } }); HuePickerBase.ValueColorProperty.Changed.AddClassHandler <HuePickerBase>((x, e) => { if (e.Sender == ValueSaturationPicker) { SelectNewColor(new HSV(H, (byte)ValueSaturationPicker.Saturation, (byte)ValueSaturationPicker.ValueColor).ToColor(), UpdatedColorReason.ValueAndSaturationChanged); } }); Slider.ValueProperty.Changed.AddClassHandler <Slider>((x, e) => { if (e.Sender == AlphaSlider) { SelectNewColor(Color.FromArgb((byte)AlphaSlider.Value, (byte)R, (byte)G, (byte)B), UpdatedColorReason.AChanged); } }); HexTextBox.TextInput += delegate { var isValid = Color.TryParse(HexTextBox.Text, out Color color); if (isValid) { SelectNewColor(color, UpdatedColorReason.HexChanged); } else { HexTextBox.Text = SelectedColor.ToString(); } }; }
/// <summary> /// Update color and focus when control made visible /// </summary> private void tmbColorMarker_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue) { (sender as UIElement)?.Focus(); if (this.DataContext is ColorChooser cc) { SelectedColor = cc.StoredColor; } HexadecimalString = SelectedColor.ToString(CultureInfo.InvariantCulture); this.updateMarkerPosition(SelectedColor); m_color = SelectedColor; } }
private void UpdateHexText() { HexTextBox.Text = SelectedColor.ToString(); }