I am trying to select/deselect XamComboEditor item upon mouse hover and by pressing Space key.
Requirement :
1) Hover mouse pointer on XamcomboEditor item
2) Pressing Space key should select/deselect that particular item
3) I want to select multiple items in the above mentioned way
Hello Bindu Doradla,
I have taken a look at the requirements you have and what you could do is to handle the XamComboEditor's PreviewKeyDown event and the MouseEnter and MouseLeave events for ComboEditorItemControl style.
Please take a look at the attached sample and let me know if you have any questions on this matter.
Hi Martin,
It is working fine as per my requirements.
I want to improvize the same by adding few more requirements.
Is there any way to select/deselect an item either on mouse hover event or keyboard up/down keys ? I am able to do both the things seperately but I dont find a way to club mouse and keyboard events together so that when mouse is hovered on one item and key up/down is pressed to focus another item, it should consider the latest focused item and select/deselect that one by pressing Space key and viceversa.
Thanks,
Bindu
Hello Bindu,
I am not sure I understand the idea that you are trying to implement. If you are able to select/deselect an item on keyboard up/down keys and the latest focused item should be selected/deselected, why do you need to select/deselect item on hovering ? It seems the two approaches are contradictory.
Please let me know if I have misunderstood your requirement.
The fix for development issue 213667 is available in the latest service release which can be downloaded from the My Keys and Downloads page.
This behavior has already been logged in our internal tracking system with a Development ID of 213667. The next step will be for a developer to review my investigation and confirm my findings or to offer a fix, or other resolution. I will leave this case open and update you with this information after the review. You can also continue to send updates to this case at any time.
You can view the status of all development issues connected to this case from the "Development Issues" tab, when viewing this case on the "My Support Requests" page of our website.
If the user uses mouse hovering for some time and keys for some time, both should be working fine simultaneously. I have implemented the same by changing PreviewKeyDown event handler in your sample. Please check the below code.
private void ComboEditorProducts_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
if (this.itemCheckBox != null)
Dispatcher.BeginInvoke(new Action(() =>
this.itemCheckBox.IsChecked = (this.itemCheckBox.IsChecked == true || this.itemCheckBox.IsChecked == null) ? false : true;
}),
System.Windows.Threading.DispatcherPriority.Background);
e.Handled = true;
}
else
XamComboEditor xamCombo = (XamComboEditor)sender;
foreach (ComboEditorItem item in xamCombo.Items)
if (item.IsFocused)
if (item.IsSelected)
item.IsSelected = false;
break;
item.IsSelected = true;
else if (e.Key == Key.Up || e.Key == Key.Down)
this.itemCheckBox = null;
The problem that I am facing now is upon unselection of an item using keys, the focus is not retained at same item. Focus is going back to earlier selected item.
Steps:
1) Lets say I have selected item1, item2
2) now I focus item2 which is already selected, press Space key and deselect it.
3) Control/Focus is moving to item1.
I want the focus to be retained at item2.