示例#1
0
        /// <summary>
        /// Returns the local value of a dependency property, if a local value is set.
        /// </summary>
        /// <param name="dependencyProperty">
        /// The DependencyProperty identifier of the property for which to retrieve the
        /// local value.
        /// </param>
        /// <returns>
        /// Returns the local value, or returns the sentinel value UnsetValue if no local
        /// value is set.
        /// </returns>
        public object ReadLocalValue(DependencyProperty dependencyProperty)
        {
            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty);

            //return dependencyProperty.Store.GetValue(storage);
            return(storage.Local);
        }
示例#2
0
        /// <summary>
        /// Sets the local value of a dependency property on a DependencyObject while not overriding a hypothetical Binding (example: when the user writes in a TextBox with a two way Binding on its Text property).
        /// </summary>
        /// <param name="dependencyProperty">The identifier of the dependency property to set.</param>
        /// <param name="value">The new local value.</param>
        public void SetLocalValue(DependencyProperty dependencyProperty, object value)
        {
#if PERFSTAT
            var t = Performance.now();
#endif
            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty, createAndSaveNewStorageIfNotExists: true);
#if PERFSTAT
            Performance.Counter("DependencyObject.SetLocalValue", t);
#endif
            INTERNAL_PropertyStore.SetLocalValue(storage, value);
        }
示例#3
0
        public void SetVisualStateValue(DependencyProperty dependencyProperty, object value)
        {
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException("No property specified");
            }

            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty, createAndSaveNewStorageIfNotExists: true);

            INTERNAL_PropertyStore.SetVisualStateValue(storage, value);
        }
示例#4
0
        public object GetVisualStateValue(DependencyProperty dependencyProperty) //todo: see if this is actually useful (to get specifically the VisualStateValue) and if so, change the GetValue into a GetVisualStateValue at the "return" line.
        {
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException("No property specified");
            }

            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty, createAndSaveNewStorageIfNotExists: true);

            return(INTERNAL_PropertyStore.GetValue(storage));
        }
示例#5
0
        internal void StyleSetterValueChanged(object sender, RoutedEventArgs e)
        {
            Setter setter = (Setter)sender;

            if (setter.Property != null)                                                                                                               // Note: it can be null for example in the XAML text editor during design time, because the "DependencyPropertyConverter" class returns "null".
            {
                INTERNAL_PropertyStorage storage = INTERNAL_PropertyStore.GetStorage(this, setter.Property, createAndSaveNewStorageIfNotExists: true); //the createAndSaveNewStorageIfNotExists's value should have no actual meaning here because the PropertyStorage should have been created when applying the style.
                HashSet2 <Style>         stylesAlreadyVisited = new HashSet2 <Style>();                                                                // Note: "stylesAlreadyVisited" is here to prevent an infinite recursion.
                INTERNAL_PropertyStore.SetLocalStyleValue(storage, Style.GetActiveValue(setter.Property, stylesAlreadyVisited));
            }
        }
        public object GetAnimationValue(DependencyProperty dependencyProperty)
        {
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException("No property specified");
            }

            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty, createAndSaveNewStorageIfNotExists: true);

            return(INTERNAL_PropertyStore.GetValue(storage));
        }
示例#7
0
        internal List <DependencyProperty> INTERNAL_PropertiesForWhichToCallPropertyChangedWhenLoadedIntoVisualTree; // When a UI element is added to the Visual Tree, we call "PropertyChanged" on all its set properties so that the control can refresh itself. However, when a property is not set, we don't call PropertyChanged. Unless the property is listed here.

        /// <summary>
        /// Returns the current effective value of a dependency property from a DependencyObject.
        /// </summary>
        /// <param name="dependencyProperty">
        /// The DependencyProperty identifier of the property for which to retrieve the
        /// value.
        /// </param>
        /// <returns>Returns the current effective value.</returns>
        public object GetValue(DependencyProperty dependencyProperty)
        {
//#if PERFSTAT
//            var t = Performance.now();
//#endif
            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty);
            //return dependencyProperty.Store.GetValue(storage);

            var tmp = INTERNAL_PropertyStore.GetValue(storage);

//#if PERFSTAT
//            Performance.Counter("DependencyObject.GetValue [" + dependencyProperty.Name + "]", t);
//#endif
            return(tmp);
        }
示例#8
0
        public void CoerceCurrentValue(DependencyProperty dependencyProperty, PropertyMetadata propertyMetadata)
        {
            var storage = INTERNAL_PropertyStore.GetStorage(this, dependencyProperty, createAndSaveNewStorageIfNotExists: true);

            INTERNAL_PropertyStore.CoerceCurrentValue(storage, propertyMetadata);
        }
示例#9
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;
                }
            }
        }