示例#1
0
文件: Style.cs 项目: yan2oo7/uno
        internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence)
        {
            if (o == null)
            {
                this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping");
                return;
            }

            using (DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence))
            {
                var flattenedSetters = CreateSetterMap();
#if !HAS_EXPENSIVE_TRYFINALLY
                try
#endif
                {
                    ResourceResolver.PushNewScope(_xamlScope);
                    foreach (var pair in flattenedSetters)
                    {
                        pair.Value(o);
                    }
                }
#if !HAS_EXPENSIVE_TRYFINALLY
                finally
#endif
                {
                    ResourceResolver.PopScope();
                }
            }
        }
示例#2
0
        internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence)
        {
            if (o == null)
            {
                this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping");
                return;
            }

            using (DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence))
            {
                var flattenedSetters = CreateSetterMap();
#if !HAS_EXPENSIVE_TRYFINALLY
                try
#endif
                {
                    ResourceResolver.PushNewScope(_xamlScope);
                    foreach (var pair in flattenedSetters)
                    {
                        pair.Value(o);
                    }

                    // Check tree for resource binding values, since some Setters may have set ThemeResource-backed values
                    (o as IDependencyObjectStoreProvider) !.Store.UpdateResourceBindings(isThemeChangedUpdate: false);
                }
#if !HAS_EXPENSIVE_TRYFINALLY
                finally
#endif
                {
                    ResourceResolver.PopScope();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of the current template.
        /// </summary>
        /// <returns>A new instance of the template</returns>
        public View LoadContent()
        {
            View view = null;

#if !HAS_EXPENSIVE_TRYFINALLY
            try
#endif
            {
                ResourceResolver.PushNewScope(_xamlScope);
                view = _viewFactory();
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                ResourceResolver.PopScope();
            }
            return(view);
        }
示例#4
0
        public View?LoadContent()
        {
            View?view = null;

#if !HAS_EXPENSIVE_TRYFINALLY
            try
#endif
            {
                ResourceResolver.PushNewScope(_xamlScope);
                if (_viewFactory != null)
                {
                    view = _viewFactory(_ownerRef?.Target);
                }
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                ResourceResolver.PopScope();
            }
            return(view);
        }
示例#5
0
文件: Style.cs 项目: Robert-Louis/Uno
        internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence)
        {
            if (o == null)
            {
                this.Log().Warn("Style.ApplyTo - Applied to null object - Skipping");
                return;
            }

            var localPrecedenceDisposable = DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence);

            var flattenedSetters = CreateSetterMap();

#if !HAS_EXPENSIVE_TRYFINALLY
            try
#endif
            {
                ResourceResolver.PushNewScope(_xamlScope);

                // This block is a manual enumeration to avoid the foreach pattern
                // See https://github.com/dotnet/runtime/issues/56309 for details
                var settersEnumerator = flattenedSetters.GetEnumerator();
                while (settersEnumerator.MoveNext())
                {
                    settersEnumerator.Current.Value(o);
                }

                // Check tree for resource binding values, since some Setters may have set ThemeResource-backed values
                (o as IDependencyObjectStoreProvider) !.Store.UpdateResourceBindings(isThemeChangedUpdate: false);
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                ResourceResolver.PopScope();
                localPrecedenceDisposable?.Dispose();
            }
        }
示例#6
0
        internal void GoToState(IFrameworkElement element, VisualState state, VisualState originalState, bool useTransitions, Action onStateChanged)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("Go to state [{0}/{1}] on [{2}]", Name, state?.Name, element);
            }

            var transition = FindTransition(originalState?.Name, state?.Name);

            EventHandler <object> onComplete = null;

            onComplete = (s, a) =>
            {
                onStateChanged();

                if (state?.Storyboard == null)
                {
                    return;
                }

                state.Storyboard.Completed -= onComplete;
            };

            EventHandler <object> onTransitionComplete = null;

            onTransitionComplete = (s, a) =>
            {
                if (transition?.Storyboard != null && useTransitions)
                {
                    transition.Storyboard.Completed -= onTransitionComplete;

                    if (state?.Storyboard != null)
                    {
                        transition.Storyboard.TurnOverAnimationsTo(state.Storyboard);
                    }
                }

                //Starts Storyboard Animation
                if (state?.Storyboard == null)
                {
                    onComplete(this, null);
                }
                else if (state != null)
                {
                    state.Storyboard.Completed += onComplete;
                    state.Storyboard.Begin();
                }
            };

            //Stops Previous Storyboard Animation
            if (originalState != null)
            {
                if (originalState.Storyboard != null)
                {
                    if (transition?.Storyboard != null)
                    {
                        originalState.Storyboard.TurnOverAnimationsTo(transition.Storyboard);
                    }
                    else if (state?.Storyboard != null)
                    {
                        originalState.Storyboard.TurnOverAnimationsTo(state.Storyboard);
                    }
                    else
                    {
                        originalState.Storyboard.Stop();
                    }
                }

                foreach (var setter in this.CurrentState.Setters.OfType <Setter>())
                {
                    if (element != null && (state?.Setters.OfType <Setter>().Any(o => o.HasSameTarget(setter, DependencyPropertyValuePrecedences.Animations, element)) ?? false))
                    {
                        // PERF: We clear the value of the current setter only if there isn't any setter in the target state
                        // which changes the same target property.

                        if (this.Log().IsEnabled(LogLevel.Debug))
                        {
                            this.Log().Debug($"Ignoring reset of setter of '{setter.Target?.Path}' as it will be updated again by '{state.Name}'");
                        }

                        continue;
                    }

                    setter.ClearValue();
                }
            }

#if !HAS_EXPENSIVE_TRYFINALLY
            try
#endif
            {
                ResourceResolver.PushNewScope(_xamlScope);

                this.CurrentState = state;
                if (this.CurrentState != null && element != null)
                {
                    foreach (var setter in this.CurrentState.Setters.OfType <Setter>())
                    {
                        setter.ApplyValue(DependencyPropertyValuePrecedences.Animations, element);
                    }
                }

                if (transition?.Storyboard == null || !useTransitions)
                {
                    onTransitionComplete(this, null);
                }
                else
                {
                    transition.Storyboard.Completed += onTransitionComplete;
                    transition.Storyboard.Begin();
                }
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                ResourceResolver.PopScope();
            }
        }