Example #1
0
        public void AttachCommandHandlers(FrameworkElement sender)
        {
            sender.AddHandler(CommandManager.PreviewCanExecuteEvent, new CanExecuteRoutedEventHandler(PreviewCanExecuteHandler), true);
              sender.AddHandler(CommandManager.CanExecuteEvent, new CanExecuteRoutedEventHandler(CanExecuteHandler), true);

              sender.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(PreviewExecutedHandler), true);
              sender.AddHandler(CommandManager.ExecutedEvent, new ExecutedRoutedEventHandler(ExecutedHandler), true);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="MouseClickWrapper"/> class with specified FrameworkElement as mouse events source and specified MouseButton 
		/// to notify about its clicks.
		/// </summary>
		/// <param name="element">The element.</param>
		/// <param name="mouseButton">The mouse button.</param>
		public MouseClickWrapper(FrameworkElement element, MouseButton mouseButton)
		{
			if (element == null)
				throw new ArgumentNullException("element");

			this.element = element;
			this.mouseButton = mouseButton;

			element.AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(OnMouseDown));
			element.AddHandler(FrameworkElement.MouseUpEvent, new MouseButtonEventHandler(OnMouseUp));
		}
Example #3
0
        /// <summary>
        /// Add an element
        /// </summary>
        /// <param name="element"></param>
        public void AddWidget(FrameworkElement element)
        {
            element.Cursor = Cursors.SizeAll;
            element.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(MouseLeftButtonDown), true);
            element.AddHandler(FrameworkElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(MouseLeftButtonUp), true);
            element.AddHandler(FrameworkElement.MouseMoveEvent, new MouseEventHandler(MouseMove), true);

            ResizingAdorner adorner = element.IsActivity() ? new ScaleResizingAdorner(element) : new ResizingAdorner(element);
            adorner.WidgetDragging += OnWidgetDragging;
            adornerLayer.Add(adorner);

            elements.Add(element, adorner);
            ElementsRightBottom.Add(element, new Point()); // element may has not loaded
        }
Example #4
0
		public DragListener(FrameworkElement target)
		{
			this.target = target;
			target.AddHandler(Mouse.MouseDownEvent, new MouseButtonEventHandler(MouseButtonDown), true);
			target.PreviewMouseMove += MouseMove;
			target.PreviewMouseLeftButtonUp += MouseLeftButtonUp;
		}
 public virtual void SetOrientationProvider(FrameworkElement control)
 {
     if (control != null)
     {
         CurrentControl = control;
         control.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(HandleOwnerMouseRightButtonDown), true);
     }
 }
Example #6
0
		public void InstallScale(FrameworkElement elem) {
			UninstallScale();
			scaleElement = elem;
			if (scaleElement == null)
				return;
			// A scrollviewer will prevent our code from getting called so use AddHandler()
			scaleElement.AddHandler(UIElement.MouseWheelEvent, new MouseWheelEventHandler(ScaleElement_MouseWheel), true);
			scaleElement.CommandBindings.AddRange(commandBindings);
			scaleElement.InputBindings.AddRange(keyBindings);
			ScaleValue = ScaleValue;
		}
Example #7
0
        public static void AttachOneShotCommandHandler(FrameworkElement element, RoutedEvent @event, RoutedEventHandler callback)
        {
            RoutedEventHandler handler = null;
              handler = (arg0, arg1) =>
              {
            element.RemoveHandler(@event, handler);

            callback(arg0, arg1);
              };

              element.AddHandler(@event, handler);
        }
Example #8
0
        /// <summary>
        /// Initializing constructor
        /// </summary>
        /// <param name="dragSource">Element to be the source of a drag operation</param>
        public DragHelper( FrameworkElement dragSource )
        {
            _dragSource = dragSource;

            _dragSource.AddHandler( FrameworkElement.MouseLeftButtonDownEvent,
                                    new MouseButtonEventHandler( OnMouseLeftButtonDown ), true );
            _dragSource.AddHandler( FrameworkElement.MouseLeftButtonUpEvent,
                                    new MouseButtonEventHandler( OnMouseLeftButtonUp ), true );
            _dragSource.AddHandler( FrameworkElement.MouseMoveEvent,
                                    new MouseEventHandler( OnMouseMove ), true );

            _dragSource.GiveFeedback += OnGiveFeedback;
        }
Example #9
0
 public void EnterAction(FrameworkElement target, BaseValueSource valueSource)
 {
     target.AddHandler(Event, Handler, HandledEventsToo);
 }
        /// <summary>
        ///     The set root visual.
        /// </summary>
        private static void SetRootVisual()
        {
            lock (Locker)
            {
                if ((RootVisual != null) || (Application.Current == null))
                {
                    return;
                }

#if (SILVERLIGHT)
                RootVisual = Application.Current.RootVisual as FrameworkElement;
#else
                RootVisual = BrowserInteropHelper.IsBrowserHosted ? null :
                    (Application.Current.MainWindow.Content as FrameworkElement) != null ? 
                    Application.Current.MainWindow.Content as FrameworkElement: Application.Current.MainWindow;
#endif
                if (RootVisual == null)
                {
                    return;
                }

                RootVisual.MouseMove += OnRootVisualMouseMove;
                RootVisual.AddHandler(
                    UIElement.MouseLeftButtonDownEvent, 
                    new MouseButtonEventHandler(OnRootVisualMouseLeftButtonDown), 
                    true);
            }
        }
Example #11
0
 public void Apply(FrameworkElement target, BaseValueSource valueSource)
 {
     target.AddHandler(Event, Handler, HandledEventsToo);
 }
Example #12
0
 protected virtual void ToggleFocusHandler()
 {
     _focusElement = GetFocusElement(_adornedElement);
     if (_visibleOnFocus && !_focusHandlerAdded)
     {
         _focusElement.AddHandler(FrameworkElement.GotFocusEvent, new RoutedEventHandler(OnGotFocus));
         _focusElement.AddHandler(FrameworkElement.LostFocusEvent, new RoutedEventHandler(OnLostFocus));
         _focusHandlerAdded = true;
     }
     else if (!_visibleOnFocus && _focusHandlerAdded)
     {
         _focusElement.RemoveHandler(FrameworkElement.GotFocusEvent, new RoutedEventHandler(OnGotFocus));
         _focusElement.RemoveHandler(FrameworkElement.LostFocusEvent, new RoutedEventHandler(OnLostFocus));
         _focusHandlerAdded = false;
     }
     if (_visibleOnFocus == false && _visible == false)
         this.Visibility = Visibility.Collapsed;
     else if (_visibleOnFocus == false && _visible == true)
         this.Visibility = Visibility.Visible;
     else
         this.Visibility = (_adornedElement.IsFocused) ? Visibility.Visible : ((_visibleOnFocus) ? Visibility.Collapsed : Visibility.Visible);
 }
Example #13
0
 private void Register()
 {
     element.AddHandler(routedEvent, (RoutedEventHandler)RoutedEventHandler);
 }
Example #14
0
		protected override void InitializeCore(FrameworkElement source)
		{
			source.AddHandler(RoutedEvent, (RoutedEventHandler)ExecuteCommand);
		}
 /// <summary>
 /// Adds the reorder completed handler.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="handler">The handler.</param>
 public static void AddReorderCompletedHandler(FrameworkElement element,
                                               RoutedPropertyChangedEventHandler<int> handler)
 {
     element.AddHandler(ReorderCompletedEvent, handler);
 }
Example #16
0
        private static void SetRootVisual()
        {
            if ((rootVisual != null) || (Application.Current == null))
            {
                return;
            }

            rootVisual = Application.Current.RootVisual as FrameworkElement;
            if (rootVisual == null)
            {
                return;
            }

            rootVisual.MouseMove += OnRootVisualMouseMove;
            rootVisual.SizeChanged += OnRootVisualSizeChanged;
            rootVisual.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnRootVisualMouseLeftButtonDown), true);
        }