ColorPickerGallery Setting Selected Item

Ribbon for WPF Forum

Posted 9 years ago by Stephen Blake
Version: 14.2.0610
Platform: .NET 3.5
Environment: Windows 7 (64-bit)
Avatar

Hi,

We are using the ColorPickerGallery as part of a larger colour editor. The picker is in the drop-down of a property grid editor and when the user opens the drop-down we want to have the current colour selected if it is one of the options (it could also be a custom colour and so not in the picker).

In our editor we bind the CategorizedItemsSource property of the gallery to a property in the code behind which we populate with default brushes as well as the user's stored custom colours. We also bind the SelectedItem property to the code behind with the aim of using this to select the current colour(brush) if possible.

The problem is that while we can set the selected item to one of the colours we supply, setting the SelectedItem to one of the auto-generated shades does not cause that colour to be selected in the gallery control. Using the binding to CategorizedItemsSource we can see all the colours, including the generated shades. If the user clicks on a generated shade it becomes highlighted, but setting it from the code behind only works for non-generated colours.

Thanks in advance

Steve

Comments (3)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Steve,

This sounds like something we'd have to debug.  Can you put together a new simple sample project that shows the issue and email that to our support address?  Please reference this thread in your email and be sure to rename the .zip file extension of the ZIP you send so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Posted 9 years ago by Stephen Blake
Avatar

Thanks for getting back to us.

Have done a little digging ourselves and it looks like we spotted the problem.

We were initializing our view and then binding to it then trying to set the selected item property, but at this stage the gallery has not yet loaded the brushes bound to its CategorizesItemsSource property. We expected this would happen when the gallery was initialized, however at that time the gallery has no items, and so our selection setting fails.

Due to time constraints we can't create a sample project for you, however if you have any thoughts/tips that may help we'd appreciate it.

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Stephen,

Updating the CategorizedItemsSource property should (in our code) immediately update the ItemsSource property.  What do you see in the ItemsSource when you are about to set the selection... has it be updated yet?  If so, the item container generator (galleries are ItemsControls) might not have run yet.


Actipro Software Support

The latest build of this product (v24.1.3) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.