当前位置: 首页>>代码示例>>C#>>正文


C# IInputElement.GetType方法代码示例

本文整理汇总了C#中IInputElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IInputElement.GetType方法的具体用法?C# IInputElement.GetType怎么用?C# IInputElement.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInputElement的用法示例。


在下文中一共展示了IInputElement.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Focus

        /// <summary>
        /// Focuses a control.
        /// </summary>
        /// <param name="control">The control to focus.</param>
        /// <param name="keyboardNavigated">
        /// Whether the control was focused by a keypress (e.g. the Tab key).
        /// </param>
        public void Focus(IInputElement control, bool keyboardNavigated = false)
        {
            if (control != null)
            {
                var scope = GetFocusScopeAncestors(control)
                    .FirstOrDefault();

                if (scope != null)
                {
                    this.Scope = scope;
                    this.SetFocusedElement(scope, control, keyboardNavigated);
                    System.Diagnostics.Debug.WriteLine("Focused " + control.GetType().Name);
                }
            }
            else if (this.Current != null)
            {
                // If control is null, set focus to the topmost focus scope.
                foreach (var scope in GetFocusScopeAncestors(this.Current).Reverse().ToList())
                {
                    IInputElement element;

                    if (this.focusScopes.TryGetValue(scope, out element))
                    {
                        this.Focus(element, keyboardNavigated);
                        break;
                    }
                }
            }
        }
开发者ID:MarkWalls,项目名称:Perspex,代码行数:36,代码来源:FocusManager.cs

示例2: KeyboardFocusChangedEventArgs

        /// <summary> 
        ///     Constructs an instance of the KeyboardFocusChangedEventArgs class.
        /// </summary> 
        /// <param name="keyboard"> 
        ///     The logical keyboard device associated with this event.
        /// </param> 
        /// <param name="timestamp">
        ///     The time when the input occured.
        /// </param>
        /// <param name="oldFocus"> 
        ///     The element that previously had focus.
        /// </param> 
        /// <param name="newFocus"> 
        ///     The element that now has focus.
        /// </param> 
        public KeyboardFocusChangedEventArgs(KeyboardDevice keyboard, int timestamp, IInputElement oldFocus, IInputElement newFocus) : base(keyboard, timestamp)
        {
            if (oldFocus != null && !InputElement.IsValid(oldFocus))
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldFocus.GetType())); 

            if (newFocus != null && !InputElement.IsValid(newFocus)) 
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, newFocus.GetType())); 

            _oldFocus = oldFocus; 
            _newFocus = newFocus;
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:26,代码来源:FocusChangedEventArgs.cs

示例3: TrackKeyboardFocus

		public void TrackKeyboardFocus()
		{
			EventManager.RegisterClassHandler(typeof(UIElement), Keyboard.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler((sender, args) =>
			{
				if (_currentFocused == args.NewFocus)
					return;
				_currentFocused = args.NewFocus;
				if (_currentFocused is FrameworkElement)
				{
					new FocusAdorner(_currentFocused as FrameworkElement);
				}
				Write((_currentFocused is FrameworkElement ? (_currentFocused as FrameworkElement).Name : "") + "<" + _currentFocused.GetType().Name + ">");
			}), true);
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:14,代码来源:Debug.cs

示例4: GetPosition

        public Point GetPosition(IInputElement relativeTo)
        {
            VerifyAccess();
            
            // Validate that relativeTo is either a UIElement or a ContentElement
            if (relativeTo != null && !InputElement.IsValid(relativeTo))
            {
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, relativeTo.GetType()));
            }
            
            PresentationSource relativePresentationSource = null;
            
            if (relativeTo != null)
            {
                DependencyObject dependencyObject = relativeTo as  DependencyObject;
                DependencyObject containingVisual = InputElement.GetContainingVisual(dependencyObject);
                if(containingVisual != null)
                {
                    relativePresentationSource = PresentationSource.CriticalFromVisual(containingVisual);
                }
            }
            else
            {
                if (_inputSource != null)
                {
                    relativePresentationSource = _inputSource.Value;
                }
            }

            // Verify that we have a valid PresentationSource with a valid RootVisual
            // - if we don't we won't be able to invoke ClientToRoot or TranslatePoint and 
            //   we will just return 0,0
            if (relativePresentationSource == null || relativePresentationSource.RootVisual == null)
            {
                return new Point(0, 0);
            }

            Point ptClient = PointUtil.ScreenToClient(_lastScreenLocation, relativePresentationSource);
            Point ptRoot      = PointUtil.ClientToRoot(ptClient, relativePresentationSource);
            Point ptRelative  = InputElement.TranslatePoint(ptRoot, relativePresentationSource.RootVisual, (DependencyObject)relativeTo);

            return ptRelative;
            
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:44,代码来源:StylusDevice.cs

示例5: Focus

        public IInputElement Focus(IInputElement element)
        {
            DependencyObject oFocus = null;
            bool forceToNullIfFailed = false; 

            // Validate that if elt is either a UIElement or a ContentElement. 
            if(element != null) 
            {
                if(!InputElement.IsValid(element)) 
                {
                    #pragma warning suppress 6506 // element is obviously not null
                    throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, element.GetType()));
                } 

                oFocus = (DependencyObject) element; 
            } 

            // If no element is given for focus, use the root of the active source. 
            if(oFocus == null && _activeSource != null)
            {
                oFocus = _activeSource.Value.RootVisual as DependencyObject;
                forceToNullIfFailed = true; 
            }
 
            Focus(oFocus, true, true, forceToNullIfFailed); 

            return (IInputElement) _focus; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:28,代码来源:KeyboardDevice.cs

示例6: CriticalCanExecute

        internal bool CriticalCanExecute(object parameter, IInputElement target, bool trusted, out bool continueRouting)
        { 
            // We only support UIElement, ContentElement, and UIElement3D
            if ((target != null) && !InputElement.IsValid(target))
            {
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, target.GetType())); 
            }
 
            if (target == null) 
            {
                target = FilterInputElement(Keyboard.FocusedElement); 
            }

            return CanExecuteImpl(parameter, target, trusted, out continueRouting);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:15,代码来源:RoutedCommand.cs

示例7: Execute

        public void Execute(object parameter, IInputElement target)
        { 
            // We only support UIElement, ContentElement and UIElement3D
            if ((target != null) && !InputElement.IsValid(target))
            {
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, target.GetType())); 
            }
 
            if (target == null) 
            {
                target = FilterInputElement(Keyboard.FocusedElement); 
            }

            ExecuteImpl(parameter, target, false);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:15,代码来源:RoutedCommand.cs

示例8: TranslateInput

        internal static void TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
        {
            if ((targetElement == null) || (inputEventArgs == null))
            {
                return;
            }

            ICommand command = null;
            IInputElement target = null;
            object parameter = null;

            // Determine UIElement/ContentElement/Neither type
            DependencyObject targetElementAsDO = targetElement as DependencyObject;
            bool isUIElement = InputElement.IsUIElement(targetElementAsDO);
            bool isContentElement = !isUIElement && InputElement.IsContentElement(targetElementAsDO);
            bool isUIElement3D = !isUIElement && !isContentElement && InputElement.IsUIElement3D(targetElementAsDO);

            // Step 1: Check local input bindings
            InputBindingCollection localInputBindings = null;
            if (isUIElement)
            {
                localInputBindings = ((UIElement)targetElement).InputBindingsInternal;
            }
            else if (isContentElement)
            {
                localInputBindings = ((ContentElement)targetElement).InputBindingsInternal;
            }
            else if (isUIElement3D)
            {
                localInputBindings = ((UIElement3D)targetElement).InputBindingsInternal;
            }
            if (localInputBindings != null)
            {
                InputBinding inputBinding = localInputBindings.FindMatch(targetElement, inputEventArgs);
                if (inputBinding != null)
                {
                    command = inputBinding.Command;
                    target = inputBinding.CommandTarget;
                    parameter = inputBinding.CommandParameter;
                }
            }

            // Step 2: If no command, check class input bindings
            if (command == null)
            {
                lock (_classInputBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        InputBindingCollection classInputBindings = _classInputBindings[classType] as InputBindingCollection;
                        if (classInputBindings != null)
                        {
                            InputBinding inputBinding = classInputBindings.FindMatch(targetElement, inputEventArgs);
                            if (inputBinding != null)
                            {
                                command = inputBinding.Command;
                                target = inputBinding.CommandTarget;
                                parameter = inputBinding.CommandParameter;
                                break;
                            }
                        }
                        classType = classType.BaseType;
                    }
                }
            }

            // Step 3: If no command, check local command bindings
            if (command == null)
            {
                // Check for the instance level ones Next
                CommandBindingCollection localCommandBindings = null;
                if (isUIElement)
                {
                    localCommandBindings = ((UIElement)targetElement).CommandBindingsInternal;
                }
                else if (isContentElement)
                {
                    localCommandBindings = ((ContentElement)targetElement).CommandBindingsInternal;
                }
                else if (isUIElement3D)
                {
                    localCommandBindings = ((UIElement3D)targetElement).CommandBindingsInternal;
                }
                if (localCommandBindings != null)
                {
                    command = localCommandBindings.FindMatch(targetElement, inputEventArgs);
                }
            }

            // Step 4: If no command, look at class command bindings
            if (command == null)
            {
                lock (_classCommandBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection;
                        if (classCommandBindings != null)
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:CommandManager.cs

示例9: GetPosition

        public Point GetPosition(IInputElement relativeTo)
        {
//             VerifyAccess();

            // Validate that relativeTo is either a UIElement or a ContentElement
            if (relativeTo != null && !InputElement.IsValid(relativeTo))
            {
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, relativeTo.GetType()));
            }

            PresentationSource relativePresentationSource = null;

            if (relativeTo != null)
            {
                DependencyObject dependencyObject = relativeTo as  DependencyObject;
                DependencyObject containingVisual = InputElement.GetContainingVisual(dependencyObject);

                if (containingVisual != null)
                {
                    relativePresentationSource = PresentationSource.CriticalFromVisual(containingVisual);
                }
            }
            else
            {
                if (_inputSource != null)
                {
                    relativePresentationSource = _inputSource.Value;
                }
            }


            // Verify that we have a valid PresentationSource with a valid RootVisual
            // - if we don't we won't be able to invoke ClientToRoot or TranslatePoint and
            //   we will just return 0,0
            if (relativePresentationSource == null || relativePresentationSource.RootVisual == null)
            {
                return new Point(0, 0);
            }

            Point ptClient;
            Point ptRoot;
            bool success;
            Point ptRelative;

            ptClient    = GetClientPosition(relativePresentationSource);
            ptRoot      = PointUtil.TryClientToRoot(ptClient, relativePresentationSource, false, out success);
            if (!success)
            {
                // ClientToRoot failed, usually because the client area is degenerate.
                // Just return 0,0
                return new Point(0, 0);
            }
            ptRelative  = InputElement.TranslatePoint(ptRoot, relativePresentationSource.RootVisual, (DependencyObject)relativeTo);

            return ptRelative;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:56,代码来源:MouseDevice.cs

示例10: Capture

        /// <summary>
        ///     Captures this device to a particular element.
        /// </summary>
        /// <param name="element">The element this device will be captured to.</param>
        /// <param name="captureMode">The type of capture to use.</param>
        /// <returns>true if capture was changed, false otherwise.</returns>
        public bool Capture(IInputElement element, CaptureMode captureMode)
        {
            VerifyAccess();

            // If the element is null or captureMode is None, ensure
            // that the other parameter is consistent.
            if ((element == null) || (captureMode == CaptureMode.None))
            {
                element = null;
                captureMode = CaptureMode.None;
            }

            UIElement uiElement;
            ContentElement contentElement;
            UIElement3D uiElement3D;
            CastInputElement(element, out uiElement, out contentElement, out uiElement3D);

            if ((element != null) && (uiElement == null) && (contentElement == null) && (uiElement3D == null))
            {
                throw new ArgumentException(SR.Get(SRID.Invalid_IInputElement, element.GetType()), "element");
            }

            if (_captured != element)
            {
                // Ensure that the new element is visible and enabled
                if ((element == null) ||
                    (((uiElement != null) && uiElement.IsVisible && uiElement.IsEnabled) ||
                    ((contentElement != null) && contentElement.IsEnabled) ||
                    ((uiElement3D != null) && uiElement3D.IsVisible && uiElement3D.IsEnabled)))
                {
                    IInputElement oldCapture = _captured;
                    _captured = element;
                    _captureMode = captureMode;

                    UIElement oldUIElement;
                    ContentElement oldContentElement;
                    UIElement3D oldUIElement3D;
                    CastInputElement(oldCapture, out oldUIElement, out oldContentElement, out oldUIElement3D);

                    if (oldUIElement != null)
                    {
                        oldUIElement.IsEnabledChanged -= OnReevaluateCapture;
                        oldUIElement.IsVisibleChanged -= OnReevaluateCapture;
                        oldUIElement.IsHitTestVisibleChanged -= OnReevaluateCapture;
                    }
                    else if (oldContentElement != null)
                    {
                        oldContentElement.IsEnabledChanged -= OnReevaluateCapture;
                    }
                    else if (oldUIElement3D != null)
                    {
                        oldUIElement3D.IsEnabledChanged -= OnReevaluateCapture;
                        oldUIElement3D.IsVisibleChanged -= OnReevaluateCapture;
                        oldUIElement3D.IsHitTestVisibleChanged -= OnReevaluateCapture;
                    }
                    if (uiElement != null)
                    {
                        uiElement.IsEnabledChanged += OnReevaluateCapture;
                        uiElement.IsVisibleChanged += OnReevaluateCapture;
                        uiElement.IsHitTestVisibleChanged += OnReevaluateCapture;
                    }
                    else if (contentElement != null)
                    {
                        contentElement.IsEnabledChanged += OnReevaluateCapture;
                    }
                    else if (uiElement3D != null)
                    {
                        uiElement3D.IsEnabledChanged += OnReevaluateCapture;
                        uiElement3D.IsVisibleChanged += OnReevaluateCapture;
                        uiElement3D.IsHitTestVisibleChanged += OnReevaluateCapture;
                    }

                    UpdateReverseInheritedProperty(/* capture = */ true, oldCapture, _captured);

                    if (oldCapture != null)
                    {
                        DependencyObject o = oldCapture as DependencyObject;
                        o.SetValue(UIElement.AreAnyTouchesCapturedPropertyKey,
                            BooleanBoxes.Box(AreAnyTouchesCapturedOrDirectlyOver(oldCapture, /* isCapture = */ true)));
                    }
                    if (_captured != null)
                    {
                        DependencyObject o = _captured as DependencyObject;
                        o.SetValue(UIElement.AreAnyTouchesCapturedPropertyKey, BooleanBoxes.TrueBox);
                    }

                    if (oldCapture != null)
                    {
                        RaiseLostCapture(oldCapture);
                    }
                    if (_captured != null)
                    {
                        RaiseGotCapture(_captured);
                    }
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:TouchDevice.cs


注:本文中的IInputElement.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。