private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.DataContext is ColorRGBProperty)
            {
                ColorRGBProperty prop  = (ColorRGBProperty)this.DataContext;
                Color            color = Color.FromRgb((byte)(prop.R * 255), (byte)(prop.G * 255), (byte)(prop.B * 255));

                ColorPickerControls.Dialogs.ColorPickerFullDialog dlg = new ColorPickerControls.Dialogs.ColorPickerFullDialog();
                dlg.InitialColor = color;
                if (dlg.ShowDialog().GetValueOrDefault(false))
                {
                    color = dlg.SelectedColor;
                }
                prop.R = (float)color.R / 255;
                prop.G = (float)color.G / 255;
                prop.B = (float)color.B / 255;

                rectColorSample.Fill = new SolidColorBrush(color);

                prop.OnPropertyChanged(new EventArgs());
            }
            else if (this.DataContext is ColorRGBAProperty)
            {
                ColorRGBAProperty prop  = (ColorRGBAProperty)this.DataContext;
                Color             color = Color.FromArgb((byte)(prop.A * 255), (byte)(prop.R * 255), (byte)(prop.G * 255), (byte)(prop.B * 255));

                ColorPickerControls.Dialogs.ColorPickerFullWithAlphaDialog dlg = new ColorPickerControls.Dialogs.ColorPickerFullWithAlphaDialog();
                dlg.InitialColor = color;
                if (dlg.ShowDialog().GetValueOrDefault(false))
                {
                    color = dlg.SelectedColor;
                }
                prop.A = (float)color.A / 255;
                prop.R = (float)color.R / 255;
                prop.G = (float)color.G / 255;
                prop.B = (float)color.B / 255;

                rectColorSample.Fill = new SolidColorBrush(color);

                prop.OnPropertyChanged(new EventArgs());
            }

            var expression = txtColor.GetBindingExpression(TextBlock.TextProperty);

            if (expression != null)
            {
                expression.UpdateSource();
            }
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is ColorRGBAProperty)
     {
         ColorRGBAProperty color = value as ColorRGBAProperty;
         return(new SolidColorBrush(Color.FromScRgb(color.A, color.R, color.G, color.B)));
     }
     if (value is ColorRGBProperty)
     {
         ColorRGBProperty color = value as ColorRGBProperty;
         return(new SolidColorBrush(Color.FromScRgb(1, color.R, color.G, color.B)));
     }
     else
     {
         return(DependencyProperty.UnsetValue);
     }
 }
 private void UserControl_DataContextChanged_1(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (this.DataContext != null)
     {
         if (this.DataContext is ColorRGBProperty)
         {
             ColorRGBProperty prop  = (ColorRGBProperty)this.DataContext;
             Color            color = Color.FromRgb((byte)(prop.R * 255), (byte)(prop.G * 255), (byte)(prop.B * 255));
             rectColorSample.Fill = new SolidColorBrush(color);
         }
         else if (this.DataContext is ColorRGBAProperty)
         {
             ColorRGBAProperty prop  = (ColorRGBAProperty)this.DataContext;
             Color             color = Color.FromRgb((byte)(prop.R * 255), (byte)(prop.G * 255), (byte)(prop.B * 255));
             rectColorSample.Fill = new SolidColorBrush(color);
         }
     }
 }