/// <summary>
        /// Returns the first child of the specified type (recursively).
        /// </summary>
        /// <typeparam name="T">The type to lookup.</typeparam>
        /// <param name="parent">The parent element.</param>
        /// <returns>The first child of the specified type.</returns>
        public static T GetChildOfType <T>(UIElement parent) where T : UIElement
        {
            if (parent == null || parent.INTERNAL_VisualChildrenInformation == null)
            {
                return(null);
            }

            foreach (INTERNAL_VisualChildInformation visualChildInformation in
#if BRIDGE
                     INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(parent.INTERNAL_VisualChildrenInformation)
#else
                     parent.INTERNAL_VisualChildrenInformation.Values
#endif
                     )
            {
                var child  = visualChildInformation.INTERNAL_UIElement;
                var result = (child as T) ?? GetChildOfType <T>(child);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Esempio n. 2
0
        global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
        {
#if BRIDGE
            return(INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(_visualStateGroups).GetEnumerator());
#else
            return(_visualStateGroups.Values.GetEnumerator());
#endif
        }
Esempio n. 3
0
        public IEnumerator <VisualStateGroup> GetEnumerator()
        {
#if BRIDGE
            return(INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(_visualStateGroups).GetEnumerator());
#else
            return(_visualStateGroups.Values.GetEnumerator());
#endif
        }
Esempio n. 4
0
        internal void INTERNAL_UpdateBindingsSource()
        {
            if (_bindingExpressions != null)
            {
                foreach (BindingExpression bindingExpression in
#if BRIDGE
                         INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(_bindingExpressions)
#else
                         _bindingExpressions.Values
#endif
                         )
                {
                    bindingExpression.OnSourceAvailable();
                }
            }
        }
        public static IEnumerable GetAllRootUIElements() // IMPORTANT: This is called via reflection from the "Visual Tree Inspector" of the Simulator. If you rename or remove it, be sure to update the Simulator accordingly!
        {
            // Include the main window:
            yield return(Window.Current);

            // And all the popups:
            foreach (var popupRoot in
#if BRIDGE
                     INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(PopupRootIdentifierToInstance)
#else
                     PopupRootIdentifierToInstance.Values
#endif
                     )
            {
                yield return(popupRoot);
            }
        }
Esempio n. 6
0
        public VisualStateGroup this[int index]
        {
            get
            {
#if BRIDGE
                return(INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(_visualStateGroups).ElementAt(index));
#else
                return(_visualStateGroups.Values.ElementAt(index));
#endif
            }
            set
            {
                //todo: refresh the VisualStates
                throw new NotImplementedException();
                _visualStateGroups[_visualStateGroups.Keys.ElementAt(index)] = value;
            }
        }
Esempio n. 7
0
        public int IndexOf(VisualStateGroup item)
        {
            int i = 0;

            while (i < _visualStateGroups.Count)
            {
#if BRIDGE
                if (INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(_visualStateGroups).ElementAt(i) == item)
#else
                if (_visualStateGroups.Values.ElementAt(i) == item)
#endif
                {
                    return(i);
                }
                ++i;
            }
            return(-1);
        }
Esempio n. 8
0
        private static void Style_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var frameworkElement = (FrameworkElement)d;

            if (!frameworkElement.INTERNAL_DoNotApplyStyle)
            {
                Style newStyle = (Style)e.NewValue;
                Style oldStyle = (Style)e.OldValue;

                Dictionary <DependencyProperty, Setter> oldStyleDictionary = new Dictionary <DependencyProperty, Setter>();
                if (oldStyle != null)
                {
                    oldStyleDictionary = oldStyle.GetDictionaryOfSettersFromStyle();
                }
                Dictionary <DependencyProperty, Setter> newStyleDictionary = new Dictionary <DependencyProperty, Setter>();
                if (newStyle != null)
                {
                    newStyleDictionary = newStyle.GetDictionaryOfSettersFromStyle();
                }

#if PERFSTAT
                var t0 = Performance.now();
#endif
                frameworkElement.RecursivelyUnregisterFromStyleChangedEvents(oldStyle);
#if PERFSTAT
                Performance.Counter("RecursivelyUnregisterFromStyleChangedEvents", t0);
#endif

#if PERFSTAT
                var t1 = Performance.now();
#endif
                frameworkElement.RecursivelyRegisterToStyleChangedEvents(newStyle);
#if PERFSTAT
                Performance.Counter("RecursivelyRegisterToStyleChangedEvents", t1);
#endif

                foreach (Setter oldSetter in
#if BRIDGE
                         INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(oldStyleDictionary)
#else
                         oldStyleDictionary.Values
#endif
                         )
                {
                    if (oldSetter.Property != null) // Note: it can be null for example in the XAML text editor during design time, because the "DependencyPropertyConverter" class returns "null".
                    {
                        if (!newStyleDictionary.ContainsKey(oldSetter.Property))
                        {
                            INTERNAL_PropertyStorage storage = INTERNAL_PropertyStore.GetStorage(d, oldSetter.Property, createAndSaveNewStorageIfNotExists: false); //the createAndSaveNewStorageIfNotExists's value should have no actual meaning here because the PropertyStorage should have been created when applying the style.
                            INTERNAL_PropertyStore.ResetLocalStyleValue(storage);
                        }
                    }

                    // Reset the information that tells which Style the Setter belongs to (this is used so that when the Value of the Setter changes, the Setter can notify its parent Style):
                    oldSetter.INTERNAL_ParentStyle = null;
                }

                foreach (Setter newSetter in
#if BRIDGE
                         INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(newStyleDictionary)
#else
                         newStyleDictionary.Values
#endif
                         )
                {
                    if (newSetter.Property != null) // Note: it can be null for example in the XAML text editor during design time, because the "DependencyPropertyConverter" class returns "null".
                    {
                        if (!oldStyleDictionary.ContainsKey(newSetter.Property) || oldStyleDictionary[newSetter.Property] != newSetter.Value)
                        {
                            INTERNAL_PropertyStorage storage = INTERNAL_PropertyStore.GetStorage(frameworkElement, newSetter.Property, createAndSaveNewStorageIfNotExists: true); //the createAndSaveNewStorageIfNotExists's value should have no actual meaning here because the PropertyStorage should have been created when applying the style.
                            INTERNAL_PropertyStore.SetLocalStyleValue(storage, newSetter.Value);
                        }
                    }

                    // Tell the setter which Style it belongs to, so that when the Value of the Setter changes, it can notify the parent Style:
                    newSetter.INTERNAL_ParentStyle = newStyle;
                }
            }
        }
        static void DetachVisualChidrenRecursively(UIElement element)
        {
            // Debug:
            //System.Diagnostics.Debug.WriteLine("Detached: " + element.GetType().Name);


            if (element._pointerExitedEventManager != null)
            {
                //todo: use element.INTERNAL_IsPointerInside for the test then set it to false.
                //bool wasPointerInElement = Convert.ToBoolean(CSHTML5.Interop.ExecuteJavaScript("$0.data_IsMouseInside", element.INTERNAL_OuterDomElement));
                //if (wasPointerInElement)
                if (element.INTERNAL_isPointerInside)
                {
#if MIGRATION
                    //element.ProcessOnMouseLeave(CSHTML5.Interop.ExecuteJavaScript("window.lastPointerPosition.event"));
                    MouseEventArgs eventArgs = new MouseEventArgs();
                    element.OnMouseLeave(eventArgs);
                    element.OnMouseLeave_ForHandledEventsToo(eventArgs);
#else
                    PointerRoutedEventArgs eventArgs = new PointerRoutedEventArgs();
                    element.OnPointerExited(eventArgs);//CSHTML5.Interop.ExecuteJavaScript("window.lastPointerPosition.event"));
                    element.OnPointerExited_ForHandledEventsToo(eventArgs);
#endif
                }
                element.isAlreadySubscribedToMouseEnterAndLeave = false;
                element.INTERNAL_isPointerInside = false;
            }

            // Call the "OnDetached" of the element. This is particularly useful for elements to clear any references they have to DOM elements. For example, the Grid will use it to set its _tableDiv to null.
            element.INTERNAL_OnDetachedFromVisualTree();

            //We detach the events from the dom element:
            element.INTERNAL_DetachFromDomEvents();

            // Call the "Unloaded" event: (note: in XAML, the "unloaded" event of the parent is called before the "unloaded" event of the children)
            element._isLoaded = false;
            if (element is FrameworkElement)
            {
                ((FrameworkElement)element).INTERNAL_RaiseUnloadedEvent();
            }

            // Traverse all elements recursively:
            if (element.INTERNAL_VisualChildrenInformation != null)
            {
                foreach (INTERNAL_VisualChildInformation childInfo in
#if BRIDGE
                         INTERNAL_BridgeWorkarounds.GetDictionaryValues_SimulatorCompatible(element.INTERNAL_VisualChildrenInformation)
#else
                         element.INTERNAL_VisualChildrenInformation.Values
#endif
                         )
                {
                    DetachVisualChidrenRecursively(childInfo.INTERNAL_UIElement);
                }
            }

            DependencyObject oldParent = element.INTERNAL_VisualParent;

            // Reset all visual-tree related information:
            element.INTERNAL_OuterDomElement                            = null;
            element.INTERNAL_InnerDomElement                            = null;
            element.INTERNAL_VisualParent                               = null;
            element.INTERNAL_VisualChildrenInformation                  = null;
            element.INTERNAL_AdditionalOutsideDivForMargins             = null;
            element.INTERNAL_DeferredRenderingWhenControlBecomesVisible = null;
            element.INTERNAL_DeferredLoadingWhenControlBecomesVisible   = null;

            // We reset the inherited properties since the element is no longer attached to its parent
            element.ResetInheritedProperties();

            if (oldParent != null)
            {
                UIElement.SynchronizeForceInheritProperties(element, oldParent);
            }
        }