public static void AddEventHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler) { UIElement uiElement = element as UIElement; if (uiElement != null) { uiElement.AddHandler(routedEvent, handler); } else { ContentElement contentElement = element as ContentElement; if (contentElement != null) { contentElement.AddHandler(routedEvent, handler); } else { UIElement3D uiElement3d = element as UIElement3D; if (uiElement3d != null) { uiElement3d.AddHandler(routedEvent, handler); } } } }
private static DependencyObject GetParentScope(DependencyObject childScope) { // Get the parent element of the childScope element DependencyObject parent = null; UIElement element = childScope as UIElement; ContentElement contentElement = (element == null) ? childScope as ContentElement : null; UIElement3D element3D = (element == null && contentElement == null) ? childScope as UIElement3D : null; if (element != null) { parent = element.GetUIParent(true); } else if (contentElement != null) { parent = contentElement.GetUIParent(true); } else if (element3D != null) { parent = element3D.GetUIParent(true); } if (parent != null) { // Get the next focus scope above this one return(FocusManager.GetFocusScope(parent)); } return(null); }
public static void RemoveHandler(this DependencyObject element, RoutedEvent routedEvent, Delegate handler) { Debug.Assert(element != null, "Element must not be null"); Debug.Assert(routedEvent != null, "RoutedEvent must not be null"); UIElement uiElement = element as UIElement; if (uiElement != null) { uiElement.RemoveHandler(routedEvent, handler); } else { ContentElement contentElement = element as ContentElement; if (contentElement != null) { contentElement.RemoveHandler(routedEvent, handler); } else { UIElement3D uiElement3D = element as UIElement3D; if (uiElement3D != null) { uiElement3D.RemoveHandler(routedEvent, handler); } } } }
public static HitTestFilterBehavior HitTestFilterInvisible(DependencyObject potentialHitTestTarget) { bool isVisible = false; bool isHitTestVisible = false; var uiElement = potentialHitTestTarget as UIElement; if (uiElement != null) { isVisible = uiElement.IsVisible; if (isVisible) { isHitTestVisible = uiElement.IsHitTestVisible; } } else { UIElement3D uiElement3D = potentialHitTestTarget as UIElement3D; if (uiElement3D != null) { isVisible = uiElement3D.IsVisible; if (isVisible) { isHitTestVisible = uiElement3D.IsHitTestVisible; } } } if (isVisible) { return(isHitTestVisible ? HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf); } return(HitTestFilterBehavior.ContinueSkipSelfAndChildren); }
private static UIElement GetTarget(DependencyObject o) { UIElement uIElement = o as UIElement; if (uIElement == null) { ContentElement contentElement = o as ContentElement; if (contentElement != null) { DependencyObject dependencyObject = PopupControlService.FindContentElementParent(contentElement); uIElement = (dependencyObject as UIElement); if (uIElement == null) { UIElement3D uIElement3D = dependencyObject as UIElement3D; if (uIElement3D != null) { uIElement = UIElementHelper.GetContainingUIElement2D(uIElement3D); } } } else { UIElement3D uIElement3D2 = o as UIElement3D; if (uIElement3D2 != null) { uIElement = UIElementHelper.GetContainingUIElement2D(uIElement3D2); } } } return(uIElement); }
private static void IterateVisualChildren(DependencyObject parent, HwndContentControlAutomationPeer.IteratorCallback callback) { if (parent == null) { return; } int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int childIndex = 0; childIndex < childrenCount; ++childIndex) { DependencyObject child = VisualTreeHelper.GetChild(parent, childIndex); UIElement element = child as UIElement; UIElement3D uiElement3D = child as UIElement3D; AutomationPeer peerForElement1; if (element != null && (peerForElement1 = UIElementAutomationPeer.CreatePeerForElement(element)) != null) { callback(peerForElement1); } else { AutomationPeer peerForElement2; if (uiElement3D != null && (peerForElement2 = UIElement3DAutomationPeer.CreatePeerForElement((UIElement3D)child)) != null) { callback(peerForElement2); } else { HwndContentControlAutomationPeer.IterateVisualChildren(child, callback); } } } }
internal static DependencyObject GetUIParentCore(DependencyObject o) { UIElement e = o as UIElement; if (e != null) { return(e.GetUIParentCore()); } else { ContentElement ce = o as ContentElement; if (ce != null) { return(ce.GetUIParentCore()); } else { UIElement3D e3D = o as UIElement3D; if (e3D != null) { return(e3D.GetUIParentCore()); } } return(null); } }
private static bool IsVisible(DependencyObject element) { while (element != null) { Visibility visibility; UIElement uiElem = element as UIElement; UIElement3D uiElem3D = element as UIElement3D; if (uiElem != null) { visibility = uiElem.Visibility; } else { visibility = uiElem3D.Visibility; } if (visibility != Visibility.Visible) { return(false); } element = UIElementHelper.GetUIParent(element); } return(true); }
private UIElement3D LoadDefaultContent() { String contentFileRelativeName; Hashtable h = (Hashtable)Application.Current.TryFindResource("ContentFiles"); // if (h != null) if ((h != null) && (h[ContentFileName] != null)) { contentFileRelativeName = System.IO.Path.Combine( SkinManager.Current.SkinFolder, (string)h[ContentFileName]); } else { contentFileRelativeName = System.IO.Path.Combine( SkinManager.DefaultSkinBaseFolder, ContentFileName); } System.Uri uri = new System.Uri( String.Format( @"/Perspective.Wpf3D;component/{0}.xaml", contentFileRelativeName), System.UriKind.Relative); // The resource has to be marked as x:Shared="false" UIElement3D content = (UIElement3D)Application.LoadComponent(uri); _namescope = NameScope.GetNameScope(content); // must occur before assigning Content _contentJustLoadedFromSkin = true; // must occur before assigning Content return(content); }
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type. static AutomationPeer?CreatePeerForElement(DependencyObject o) { return(o switch { UIElement uiElement => UIElementAutomationPeer.CreatePeerForElement(uiElement), UIElement3D uiElement3D => UIElement3DAutomationPeer.CreatePeerForElement(uiElement3D), _ => null, });
/// <summary> /// Defines the transform to apply to the 3D element. /// </summary> /// <param name="element">The 3D element.</param> /// <returns>A TranslateTransform3D object.</returns> protected override Transform3D ComputeTransform(UIElement3D element) { int x = GetX(element); int y = GetY(element); int z = GetZ(element); return(new TranslateTransform3D(x, y, z)); }
internal static bool InvalidateAutomationPeer( DependencyObject o, out UIElement e, out ContentElement ce, out UIElement3D e3d) { e = null; ce = null; e3d = null; AutomationPeer ap = null; e = o as UIElement; if (e != null) { if (e.HasAutomationPeer == true) { ap = e.GetAutomationPeer(); } } else { ce = o as ContentElement; if (ce != null) { if (ce.HasAutomationPeer == true) { ap = ce.GetAutomationPeer(); } } else { e3d = o as UIElement3D; if (e3d != null) { if (e3d.HasAutomationPeer == true) { ap = e3d.GetAutomationPeer(); } } } } if (ap != null) { ap.InvalidateAncestorsRecursive(); // Check for parent being non-null while stopping as we don't want to stop in between due to peers not connected to AT // those peers sometimes gets created to serve for various patterns. // e.g: ScrollViewAutomationPeer for Scroll Pattern in case of ListBox. if (ap.GetParent() != null) { return(false); } } return(true); }
/// public static AutomationPeer FromElement(UIElement3D element) { if (element == null) { throw new ArgumentNullException("element"); } return(element.GetAutomationPeer()); }
private bool ExecuteImpl(object parameter, IInputElement target, bool userInitiated) { // If blocked by rights-management fall through and return false if ((target != null) && !IsBlockedByRM) { UIElement targetUIElement = target as UIElement; ContentElement targetAsContentElement = null; UIElement3D targetAsUIElement3D = null; // Raise the Preview Event and check for Handled value, and // Raise the regular ExecuteEvent. ExecutedRoutedEventArgs args = new ExecutedRoutedEventArgs(this, parameter); args.RoutedEvent = CommandManager.PreviewExecutedEvent; if (targetUIElement != null) { targetUIElement.RaiseEvent(args, userInitiated); } else { targetAsContentElement = target as ContentElement; if (targetAsContentElement != null) { targetAsContentElement.RaiseEvent(args, userInitiated); } else { targetAsUIElement3D = target as UIElement3D; if (targetAsUIElement3D != null) { targetAsUIElement3D.RaiseEvent(args, userInitiated); } } } if (!args.Handled) { args.RoutedEvent = CommandManager.ExecutedEvent; if (targetUIElement != null) { targetUIElement.RaiseEvent(args, userInitiated); } else if (targetAsContentElement != null) { targetAsContentElement.RaiseEvent(args, userInitiated); } else if (targetAsUIElement3D != null) { targetAsUIElement3D.RaiseEvent(args, userInitiated); } } return(args.Handled); } return(false); }
///<summary> /// This static helper creates an AutomationPeer for the specified element and /// caches it - that means the created peer is going to live long and shadow the /// element for its lifetime. The peer will be used by Automation to proxy the element, and /// to fire events to the Automation when something happens with the element. /// The created peer is returned from this method and also from subsequent calls to this method /// and <seealso cref="FromElement"/>. The type of the peer is determined by the /// <seealso cref="UIElement3D.OnCreateAutomationPeer"/> virtual callback. If UIElement3D does not /// implement the callback, there will be no peer and this method will return 'null' (in other /// words, there is no such thing as a 'default peer'). ///</summary> public static AutomationPeer CreatePeerForElement(UIElement3D element) { if (element == null) { throw new ArgumentNullException("element"); } return(element.CreateAutomationPeer()); }
/// public UIElement3DAutomationPeer(UIElement3D owner) { if (owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; }
public void setArrowVisible(UIElement3D arrowContainer, bool visible) { if (visible) { arrowContainer.Visibility = Visibility.Visible; } else { arrowContainer.Visibility = Visibility.Collapsed; } }
private void UpdateManipulators(ICollection <IManipulator> updatedManipulators) { // Clear out the old removed collection and use it to store // the new current collection. The old current collection // will be used to generate the new removed collection. _removedManipulators.Clear(); var temp = _removedManipulators; _removedManipulators = _currentManipulators; _currentManipulators = temp; // End the manipulation if the element is not // visible anymore UIElement uie = _currentContainer as UIElement; if (uie != null) { if (!uie.IsVisible) { return; } } else { UIElement3D uie3D = _currentContainer as UIElement3D; if (uie3D != null && !uie3D.IsVisible) { return; } } // For each updated manipulator, convert it to the correct format in the // current collection and remove it from the removed collection. What is left // in the removed collection will be the manipulators that were removed. foreach (IManipulator updatedManipulator in updatedManipulators) { // int id = updatedManipulator.Id; _removedManipulators.Remove(id); // This manipulator was not removed Point position = updatedManipulator.GetPosition(_currentContainer); position = _manipulationDevice.GetTransformedManipulatorPosition(position); _currentManipulators[id] = new Manipulator2D(id, (float)position.X, (float)position.Y); } }
/// <summary> /// Defines the transform to apply to the 3D element. /// </summary> /// <param name="element">The 3D element.</param> /// <returns>A TranslateTransform3D object.</returns> protected override Transform3D ComputeTransform(UIElement3D element) { int x = GetX(element); int y = GetY(element); double offsetX = 0d; double offsetY = 0d; double minLength = Math.Cos(GeometryHelper.DegreeToRadian(30d)); if (HasTriangleCellCap) { offsetX = minLength * (x * 2d + y); offsetY = y * 1.5; } else { offsetX = x * 1.5; offsetY = minLength * (y * 2d + x); } return(new TranslateTransform3D(offsetX, offsetY, 0)); }
/// <summary> /// This method is called by automation framework to trigger synchronized input processing. /// </summary> /// <param name="inputType"> Synchronized input type</param> void ISynchronizedInputProvider.StartListening(SynchronizedInputType inputType) { if (inputType != SynchronizedInputType.KeyDown && inputType != SynchronizedInputType.KeyUp && inputType != SynchronizedInputType.MouseLeftButtonDown && inputType != SynchronizedInputType.MouseLeftButtonUp && inputType != SynchronizedInputType.MouseRightButtonDown && inputType != SynchronizedInputType.MouseRightButtonUp) { throw new ArgumentException(SR.Get(SRID.Automation_InvalidSynchronizedInputType, inputType)); } UIElement e = _owner as UIElement; if (e != null) { if (!e.StartListeningSynchronizedInput(inputType)) { throw new InvalidOperationException(SR.Get(SRID.Automation_RecursivePublicCall)); } } else { ContentElement ce = _owner as ContentElement; if (ce != null) { if (!ce.StartListeningSynchronizedInput(inputType)) { throw new InvalidOperationException(SR.Get(SRID.Automation_RecursivePublicCall)); } } else { UIElement3D e3D = (UIElement3D)_owner; if (!e3D.StartListeningSynchronizedInput(inputType)) { throw new InvalidOperationException(SR.Get(SRID.Automation_RecursivePublicCall)); } } } }
internal static void RaiseAutomationEvents() { if (InputElement.IsUIElement(InputManager.ListeningElement)) { UIElement e = (UIElement)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(e.GetAutomationPeer()); } else if (InputElement.IsContentElement(InputManager.ListeningElement)) { ContentElement ce = (ContentElement)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(ce.GetAutomationPeer()); } else if (InputElement.IsUIElement3D(InputManager.ListeningElement)) { UIElement3D e3D = (UIElement3D)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(e3D.GetAutomationPeer()); } }
internal static bool IsElementEnabled(DependencyObject o) { bool result = true; UIElement uIElement = o as UIElement; ContentElement contentElement = (uIElement == null) ? (o as ContentElement) : null; UIElement3D uIElement3D = (uIElement == null && contentElement == null) ? (o as UIElement3D) : null; if (uIElement != null) { result = uIElement.IsEnabled; } else if (contentElement != null) { result = contentElement.IsEnabled; } else if (uIElement3D != null) { result = uIElement3D.IsEnabled; } return(result); }
internal static void InvalidateAutomationAncestors(DependencyObject o) { UIElement e = null; UIElement3D e3d = null; ContentElement ce = null; Stack <DependencyObject> branchNodeStack = new Stack <DependencyObject>(); bool continueInvalidation = true; while (o != null && continueInvalidation) { continueInvalidation &= InvalidateAutomationPeer(o, out e, out ce, out e3d); // // Invoke InvalidateAutomationAncestorsCore // bool continuePastVisualTree = false; if (e != null) { continueInvalidation &= e.InvalidateAutomationAncestorsCore(branchNodeStack, out continuePastVisualTree); // Get element's visual parent o = e.GetUIParent(continuePastVisualTree); } else if (ce != null) { continueInvalidation &= ce.InvalidateAutomationAncestorsCore(branchNodeStack, out continuePastVisualTree); // Get element's visual parent o = (DependencyObject)ce.GetUIParent(continuePastVisualTree); } else if (e3d != null) { continueInvalidation &= e3d.InvalidateAutomationAncestorsCore(branchNodeStack, out continuePastVisualTree); // Get element's visual parent o = e3d.GetUIParent(continuePastVisualTree); } } }
// Add a preopportunity handler for the logical parent incase of templated element. internal static void AddParentPreOpportunityHandler(DependencyObject o, EventRoute route, RoutedEventArgs args) { // If the logical parent is different from visual parent then add handler on behalf of the // parent into the route. This is to cover the templated elements, where event could be // handled by one of the child visual element but we should consider it as if event is handled by // parent element ( logical parent). DependencyObject visualParent = null; if (o is Visual || o is Visual3D) { visualParent = UIElementHelper.GetUIParent(o); } DependencyObject logicalParent = SynchronizedInputHelper.GetUIParentCore(o); if (logicalParent != null && logicalParent != visualParent) { UIElement e = logicalParent as UIElement; if (e != null) { e.AddSynchronizedInputPreOpportunityHandler(route, args); } else { ContentElement ce = logicalParent as ContentElement; if (ce != null) { ce.AddSynchronizedInputPreOpportunityHandler(route, args); } else { UIElement3D e3D = logicalParent as UIElement3D; if (e3D != null) { e3D.AddSynchronizedInputPreOpportunityHandler(route, args); } } } } }
internal static bool IsElementEnabled(DependencyObject o) { bool enabled = true; UIElement uie = o as UIElement; ContentElement ce = (uie == null) ? o as ContentElement : null; UIElement3D uie3D = (uie == null && ce == null) ? o as UIElement3D : null; if (uie != null) { enabled = uie.IsEnabled; } else if (ce != null) { enabled = ce.IsEnabled; } else if (uie3D != null) { enabled = uie3D.IsEnabled; } return(enabled); }
////<summary> /// Cancel synchronized input processing. ///</summary> void ISynchronizedInputProvider.Cancel() { UIElement e = _owner as UIElement; if (e != null) { e.CancelSynchronizedInput(); } else { ContentElement ce = _owner as ContentElement; if (ce != null) { ce.CancelSynchronizedInput(); } else { UIElement3D e3D = (UIElement3D)_owner; e3D.CancelSynchronizedInput(); } } }
/// <summary> /// Returns the UIElement target /// </summary> private static UIElement GetTarget(DependencyObject o) { UIElement uie = o as UIElement; if (uie == null) { ContentElement ce = o as ContentElement; if (ce != null) { DependencyObject ceParent = FindContentElementParent(ce); // attempt to cast to a UIElement uie = ceParent as UIElement; if (uie == null) { // target can't be a UIElement3D - so get the nearest containing UIElement UIElement3D uie3D = ceParent as UIElement3D; if (uie3D != null) { uie = UIElementHelper.GetContainingUIElement2D(uie3D); } } } else { // it wasn't a UIElement or ContentElement, try one last cast to UIElement3D // target can't be a UIElement3D - so get the nearest containing UIElement UIElement3D uie3D = o as UIElement3D; if (uie3D != null) { uie = UIElementHelper.GetContainingUIElement2D(uie3D); } } } return(uie); }
internal static DependencyObject GetUIParent(DependencyObject child, bool continuePastVisualTree) { DependencyObject parent = null; DependencyObject myParent = null; // Try to find a UIElement parent in the visual ancestry. if (child is Visual) { myParent = ((Visual)child).InternalVisualParent; } else { myParent = ((Visual3D)child).InternalVisualParent; } parent = InputElement.GetContainingUIElement(myParent) as DependencyObject; // If there was no UIElement parent in the visual ancestry, // check along the logical branch. if (parent == null && continuePastVisualTree) { UIElement childAsUIElement = child as UIElement; if (childAsUIElement != null) { parent = InputElement.GetContainingInputElement(childAsUIElement.GetUIParentCore()) as DependencyObject; } else { UIElement3D childAsUIElement3D = child as UIElement3D; if (childAsUIElement3D != null) { parent = InputElement.GetContainingInputElement(childAsUIElement3D.GetUIParentCore()) as DependencyObject; } } } return(parent); }
protected bool ValidateUIElement3DForCapture(UIElement3D element) { return(element.IsEnabled && element.IsVisible && element.IsHitTestVisible); }
// Walk up the parent chain to find the closest element with IsFocusScope=true private static DependencyObject _GetFocusScope(DependencyObject d) { if (d == null) { return(null); } if ((bool)d.GetValue(IsFocusScopeProperty)) { return(d); } // Step 1: Walk up the logical tree UIElement uiElement = d as UIElement; if (uiElement != null) { DependencyObject logicalParent = uiElement.GetUIParentCore(); if (logicalParent != null) { return(GetFocusScope(logicalParent)); } } else { ContentElement ce = d as ContentElement; if (ce != null) { DependencyObject logicalParent = ce.GetUIParent(true); if (logicalParent != null) { return(_GetFocusScope(logicalParent)); } } else { UIElement3D uiElement3D = d as UIElement3D; if (uiElement3D != null) { DependencyObject logicalParent = uiElement3D.GetUIParentCore(); if (logicalParent != null) { return(GetFocusScope(logicalParent)); } } } } // Step 2: Walk up the visual tree if (d is Visual || d is Visual3D) { DependencyObject visualParent = VisualTreeHelper.GetParent(d); if (visualParent != null) { return(_GetFocusScope(visualParent)); } } // If visual and logical parent is null - then the element is implicit focus scope return(d); }