public void AttachToElement(FrameworkElement element)
        {
            //if (TargetElement != null)
            //{
            //   if (ReferenceEquals(TargetElement.ElementSelectionService, element))
            //   {
            //      log.DebugFormat("Extender {0} is already attached to element {1}", this, element);
            //      return;
            //   }
            //   throw new InvalidOperationException("Cannot re-attach an attached extender");
            //}

            TargetElementProxy = UIServiceProvider.GetService <IMultiSelectionService>(element);
            SetSelectionExtender(element, this);
            var selectionView = GetSelectionView(element);

            this.AttachSelectionModel(null, selectionView);
            TargetElementProxy.SelectionChanged += TargetElement_SelectionChanged;

            currentItemTracker = UIServiceProvider.GetService <ICurrentItemService>(element, false);
            currentItemTracker.CurrentChanged         += new EventHandler(currentItemTracker_CurrentChanged);
            currentItemTracker.PreviewCurrentChanging += CurrentItemTracker_PreviewCurrentChanging;
            //if (currentItemTracker != null)
            //{
            //   selectionModeManager = new SelectionModeManager(TargetElement);
            //}

            var inputService = UIServiceProvider.GetService <InputService>(TargetElement);

            inputService.RegisterMouseActionGestures(ToggleSelection, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Control));
            inputService.RegisterKeyActionGestures(ToggleSelection, new KeyGesturesFactory(Key.Space, ModifierKeys.Control));
            //inputService.RegisterMouseActionGestures(SelectRange, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Shift));
        }
 public void DetachFromElement(FrameworkElement element)
 {
     if (TargetElementProxy == null)
     {
         log.WarnFormat("Detaching extender {0} from {1} for the second time", this, element);
         return;
     }
     SetSelectionExtender(element, null);
     TargetElementProxy.SelectionChanged -= TargetElement_SelectionChanged;
     UnregisterSelectionModelEvents(GetSelectionView(TargetElementProxy.Element));
     TargetElementProxy = null;
 }
 public void Initialize(IMultiSelectionService element, ICurrentItemService currentItemTracker)
 {
     ElementSelectionService = element;
     CurrentItemTracker      = currentItemTracker;
 }