internal static IObservable<CustomDragDropKeyStates> GetKeyStateChangedOnSelfAndSiblingsAlways(this UIElement that, CustomDragDropKeyStates initialState) { IEnumerable<UIElement> enumerable = from popup in that.GetVisualDescendants().OfType<Popup>() select popup.Child into popupRoot where popupRoot != null select popupRoot; return GetKeyStateChanged(Enumerable.Aggregate<IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>>(from popupRoot in enumerable select popupRoot.GetMouseLeftButtonDownAlways(), that.GetMouseLeftButtonDownAlways(), (Func<IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>>) ((left, right) => left.Merge<Event<MouseButtonEventArgs>>(right))), Enumerable.Aggregate<IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>>(from popupRoot in enumerable select popupRoot.GetMouseLeftButtonUpAlways(), that.GetMouseLeftButtonUpAlways(), (Func<IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>, IObservable<Event<MouseButtonEventArgs>>>) ((left, right) => left.Merge<Event<MouseButtonEventArgs>>(right))), Enumerable.Aggregate<IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>>(from popupRoot in enumerable select popupRoot.GetKeyUpAlways(), that.GetKeyUpAlways(), (Func<IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>>) ((left, right) => left.Merge<Event<KeyEventArgs>>(right))), Enumerable.Aggregate<IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>>(from popupRoot in enumerable select popupRoot.GetKeyDownAlways(), that.GetKeyDownAlways(), (Func<IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>, IObservable<Event<KeyEventArgs>>>) ((left, right) => left.Merge<Event<KeyEventArgs>>(right))), initialState); }
public static void DoDragDrop(DependencyObject dragSource, object data, CustomDragDropEffects allowedEffects, CustomDragDropKeyStates initialKeyState) { _dragOperationInProgress = new CustomDragOperation(dragSource, data, allowedEffects, initialKeyState); _dragOperationInProgress.Subscribe<CustomDragDropEffects>(delegate (CustomDragDropEffects effects) { CustomDragDropCompletedEventArgs args = new CustomDragDropCompletedEventArgs { Effects = effects }; OnDragCompleted(args); }); }
internal static IObservable<CustomDragDropKeyStates> GetKeyStateChangedAlways(this UIElement that, CustomDragDropKeyStates initialState) { return GetKeyStateChanged(that.GetMouseLeftButtonDownAlways(), that.GetMouseLeftButtonUpAlways(), that.GetKeyDownAlways(), that.GetKeyUpAlways(), initialState); }
private static IObservable<CustomDragDropKeyStates> GetKeyStateChanged(IObservable<Event<MouseButtonEventArgs>> mouseDownObservable, IObservable<Event<MouseButtonEventArgs>> mouseUpObservable, IObservable<Event<KeyEventArgs>> keyDownObservable, IObservable<Event<KeyEventArgs>> keyUpObservable, CustomDragDropKeyStates initialState) { return mouseDownObservable.Select<Event<MouseButtonEventArgs>, Tuple<bool, CustomDragDropKeyStates>>(ev => Tuple.Create<bool, CustomDragDropKeyStates>(true, CustomDragDropKeyStates.LeftMouseButton)).Merge<Tuple<bool, CustomDragDropKeyStates>>(mouseUpObservable.Select<Event<MouseButtonEventArgs>, Tuple<bool, CustomDragDropKeyStates>>(ev => Tuple.Create<bool, CustomDragDropKeyStates>(false, CustomDragDropKeyStates.LeftMouseButton))).Merge<Tuple<bool, CustomDragDropKeyStates>>(keyUpObservable.Select<Event<KeyEventArgs>, Tuple<bool, CustomDragDropKeyStates>>(ev => Tuple.Create<bool, CustomDragDropKeyStates>(false, ToDragDropKeyStates(ev.EventArgs.Key)))).Merge<Tuple<bool, CustomDragDropKeyStates>>(keyDownObservable.Select<Event<KeyEventArgs>, Tuple<bool, CustomDragDropKeyStates>>(ev => Tuple.Create<bool, CustomDragDropKeyStates>(true, ToDragDropKeyStates(ev.EventArgs.Key)))).Scan<Tuple<bool, CustomDragDropKeyStates>, CustomDragDropKeyStates>(initialState, delegate (CustomDragDropKeyStates acc, Tuple<bool, CustomDragDropKeyStates> current) { if (current.Item1) { return (acc | ((CustomDragDropKeyStates) current.Item2)); } return (acc & ((CustomDragDropKeyStates) ~current.Item2)); }); }