Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
815
xamColorPicker does not handle when user clicks outside of the control
posted

We are using XamColorPicker and need to know whether or not a user clicked on a color to close the color picker control.   We have the following setup:

- A color picker on a WPF window
- SelectedColor is bound to a property
- IsDropDownOpen bound to a property
- An event handler for DropDownClosing
- An event handler for DropDownClosed

- A change in the selected color in the color picker should change the background color of the WPF window.  A hover over a color in the color picker should not change the color of the background of the WPF window.

How can we handle the following cases?
1. Drop down the control and close it again using the drop down button without hovering over any color or clicking on any color
     We want to take no action

2. Drop down the control, hover over one or more colors, then click outside of the control to close the control.  The user would not click on to select any of the colors.
      We want to take no action and to not update anything based on the update to the property SelectedColor is bound to

3. Drop down the control, hover over one or more colors, then click on a color to close the control
      We want to update the WPF window's background color only one time with the final color clicked on by the user

How can we handle the case where the control is closed and the user did not select a color and the other case where the user selected a color.

Handling just the control is closed event or when the IsDropDownOpen property is set to false does not work.

Please add a Boolean property to the control indicating whether or not the user clicked on a color to select it.  This property would be set to false when the control is opened and set to true along with updating the selected color only after the user selects a color.   

This would let us handle a color selection by binding to the IsDropDown open property and in its set method using this logic,

private System.Windows.Media.Color lastSelectedColor;

private Boolean b;

public property bool IsColorPickerDropDownOpen

{

get { return b; }

set

  {

    if (value == true)

        lastSelectedColor = colorPickerControl.SelectedColor;

    else

       if (colorPickerControl.HasUserSelectedColor == true) && (colorPickerControl.SelectedColor != lastSelectedColor)

           {

             //handle color changed - newly selected color is colorPickerControl.SelectedColor

           }

      this.b = value

      OnPropertyChanged("IsColorPickerDropDownOpen");

  }

}

This is a different variant of this earlier question: http://ko.infragistics.com/community/forums/t/64357.aspx

This should be simple to use and not require adding dispatcher calls, retemplating, etc.

The control as it is works to update the last hovered over color instead of the selected one.

Parents
  • 815
    posted

    We need this color updated only if the user clicks on a color to select it because it will be eventually used to re-color the vertices of a 3D object having ~500,000 vertices.  Recomputing the colors of the vertices involves multiple computation steps and is non-trivial to compute.

    The 3D object rendered has a varying color based on the user selected color and a variance selected by another control on the WPF window.

Reply Children
No Data