private void OnselectionModelChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedIndices") { bool oldValue = IsSelected; var groupIndex = GetGroupIndex(); bool newValue = groupIndex >= 0 ? SelectionModel.IsSelected(groupIndex, RepeatedIndex).Value : false; if (oldValue != newValue) { IsSelected = newValue; // AutomationEvents.PropertyChanged is used as a value that means dont raise anything AutomationEvents eventToRaise = oldValue ? (SelectionModel.SingleSelect ? AutomationEvents.PropertyChanged : AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection) : (SelectionModel.SingleSelect ? AutomationEvents.SelectionItemPatternOnElementSelected : AutomationEvents.SelectionItemPatternOnElementAddedToSelection); if (eventToRaise != AutomationEvents.PropertyChanged && AutomationPeer.ListenerExists(eventToRaise)) { var peer = FrameworkElementAutomationPeer.CreatePeerForElement(this); peer.RaiseAutomationEvent(eventToRaise); } } } }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (SelectionModel != null) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && !SelectionModel.SingleSelect) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { SelectionModel.DeselectRangeFromAnchor(RepeatedIndex); } else { SelectionModel.SelectRangeFromAnchor(RepeatedIndex); } } else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (SelectionModel.IsSelected(RepeatedIndex).Value) { SelectionModel.Deselect(RepeatedIndex); } else { SelectionModel.Select(RepeatedIndex); } } else { SelectionModel.Select(RepeatedIndex); this.Focus(); } } base.OnMouseLeftButtonDown(e); }