xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.91k stars 878 forks source link

[ColorCanvas] Incorrect Hexadecimal state when RGB is set to 0,0,0 (Black) #1650

Open mauclores opened 3 years ago

mauclores commented 3 years ago

Version: 4.0.2

Issue: When passing RGB values as 0, 0, 0 (Black) programmatically, the HexadecimalString value seems to be not updated automatically (it becomes empty as screenshot below). This causes for the RGB sliders to be disabled (cannot be dragged).

colorCanvas

Snippet:

XceedBoucherS commented 3 years ago

Hello, I tried it with v4.0.2 on NuGet and it worked without disabling the slider. Here's my code: <StackPanel> <xctk:ColorCanvas UsingAlphaChannel="False" R="{Binding Path=CustomFontR, Mode=TwoWay}" G="{Binding Path=CustomFontG, Mode=TwoWay}" B="{Binding Path=CustomFontB, Mode=TwoWay}" /> <Button Content="TEST" Click="Button_Click" /> </StackPanel>

` public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { InitializeComponent();

  this.DataContext = this;
  this.CustomFontR = 255;
  this.CustomFontG = 0;
  this.CustomFontB = 0;
}

private byte _r;
private byte _g;
private byte _b;

public byte CustomFontR
{
  get
  {
    return _r;
  }
  set
  {
    _r = value;
    this.OnPropertyChanged( "CustomFontR" );
  }
}
public byte CustomFontG
{
  get
  {
    return _g;
  }
  set
  {
    _g = value;
    this.OnPropertyChanged( "CustomFontG" );
  }
}
public byte CustomFontB
{
  get
  {
    return _b;
  }
  set
  {
    _b = value;
    this.OnPropertyChanged( "CustomFontB" );
  }
}

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged( string propertyName )
{
  var handler = this.PropertyChanged;
  if( handler == null )
    return;

  handler.Invoke( this, new PropertyChangedEventArgs( propertyName ) );
}

#endregion

private void Button_Click( object sender, RoutedEventArgs e )
{
  this.CustomFontB = 0;
  this.CustomFontR = 0;
  this.CustomFontG = 0;
}

}`

Did I miss something ? Thank you.

mauclores commented 3 years ago

Hello, Could you change the intinialized CustomFontR from 255 to 0? (And try to view the picker without pressing the button)

Thank you.

XceedBoucherS commented 3 years ago

Hi, Thank you for the clarification. Here's what happens. In the ColorCanvas, the default value for R/G/B is 0/0/0. and for SelectedColor, its null. When you set the R/G/B to 0/0/0, nothing is changed and so the SelectedColor remains unchanged at null. As soon as R/G/B is modified or you click in the panel to select a new color, everything works fine.

Try setting a startValue for SelectedColor, let's say Blue, in XAML. From there, when the R/G/B values are modified, the SelectedColor will follow: <xctk:ColorCanvas UsingAlphaChannel="False" SelectedColor="Blue" R="{Binding Path=CustomFontR, Mode=TwoWay}" G="{Binding Path=CustomFontG, Mode=TwoWay}" B="{Binding Path=CustomFontB, Mode=TwoWay}" />

mauclores commented 3 years ago

Hello, Thank you for the explanation. I have confirmed that your solution fixed the issue.

Thank you.