Posted 13 years ago by Kasper
Version: 11.1.0545
Avatar
What's the best way to hook up the SpectrumSlice control with its "frieds", SpectrumSlider and ColorComponentSlider? I'm trying to create a color dialog using these lovely controls, but because I want some distance between the slice and the slider, I can't just use the SpectrumColorPicker control (or can I?). Since I want to be able to set a common selected color for the dialog (color can be selected in other ways than just the ones used by the Actipro controls), I have defined a dependency property on my Window called SelectedColor/SelectedColorProperty. I have the following markup:

<shared:SpectrumSlice                             
                            SelectedColor="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=my:ColorDialog, AncestorLevel=1}, Path=SelectedColor, Mode=TwoWay}" 
                            BaseColor="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=my:ColorDialog, AncestorLevel=1}, Path=SelectedColor, Mode=OneWay}" />

<shared:SpectrumSlider SelectedColor="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=my:ColorDialog, AncestorLevel=1}, Path=SelectedColor, Mode=TwoWay}" />
Unfortunately, it doesn't work like it does in the sample browser, where the two controls are used inside the SpectrumColorPicker. I'm not sure that I'm using the BaseColor property correctly, but if I don't use it at all, nothing seems to be working :). The problem is that when I click on the slider, the marker is reset and when I click somewhere in the slice, the BaseColor changes, making the slice look a bit weird. I just want the exact same behavior as in the SpectrumColorPicker, but with the ability to control e.g. the distance and border on the two separate controls. Please guide me :)

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

The SpectrumSlice.BaseColor should be bound to the SpectrumSlider.SelectedColor property. Then the SpectrumSlider.Value should be keep in sync with the SpectrumSlice's color, but it should be set to the Hue, from the HSB value. You can use our UIColor class to get this value, so something like:
this.Slider.Value = UIColor.FromColor(selectedColor).HsbHue;


Actipro Software Support

Posted 13 years ago by Kasper
Avatar
I see. But in my case, the current color can come from a wide range of places, including a user customizable list, an HTML hex input textbox, the R, G and B sliders and so on. I thought that my solution with the SelectedColorProperty would be a great way to be able to bind to all these possible changes, but perhaps it's not possible to combine like in my example?
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

If you have one "main" SelectedColor property, then you should be able to use it to keep the SpectrumSlider in sync. That's effectively what we do in the SpectrumColorPicker. You wouldn't be able use bindings alone, as you'd need to convert to the selected color to it's hue for the slider (as shown above).


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.