Ejemplo n.º 1
0
 // Token: 0x060003AF RID: 943 RVA: 0x0000A87B File Offset: 0x00008A7B
 internal ValueSource(BaseValueSourceInternal source, bool isExpression, bool isAnimated, bool isCoerced, bool isCurrent)
 {
     this._baseValueSource = (BaseValueSource)source;
     this._isExpression    = isExpression;
     this._isAnimated      = isAnimated;
     this._isCoerced       = isCoerced;
     this._isCurrent       = isCurrent;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepare the element to display the item.  This may involve
        /// applying styles, setting bindings, etc.
        /// </summary>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);

            // For certain known types, automatically change their default style
            // to point to a ToolBar version.
            FrameworkElement fe = element as FrameworkElement;

            if (fe != null)
            {
                Type        feType      = fe.GetType();
                ResourceKey resourceKey = null;
                if (feType == typeof(Button))
                {
                    resourceKey = ButtonStyleKey;
                }
                else if (feType == typeof(ToggleButton))
                {
                    resourceKey = ToggleButtonStyleKey;
                }
                else if (feType == typeof(Separator))
                {
                    resourceKey = SeparatorStyleKey;
                }
                else if (feType == typeof(CheckBox))
                {
                    resourceKey = CheckBoxStyleKey;
                }
                else if (feType == typeof(RadioButton))
                {
                    resourceKey = RadioButtonStyleKey;
                }
                else if (feType == typeof(ComboBox))
                {
                    resourceKey = ComboBoxStyleKey;
                }
                else if (feType == typeof(TextBox))
                {
                    resourceKey = TextBoxStyleKey;
                }
                else if (feType == typeof(Menu))
                {
                    resourceKey = MenuStyleKey;
                }

                if (resourceKey != null)
                {
                    bool hasModifiers;
                    BaseValueSourceInternal vs = fe.GetValueSource(StyleProperty, null, out hasModifiers);

                    if (vs <= BaseValueSourceInternal.ImplicitReference)
                    {
                        fe.SetResourceReference(StyleProperty, resourceKey);
                    }
                    fe.DefaultStyleKey = resourceKey;
                }
            }
        }
Ejemplo n.º 3
0
        internal static bool IsFocusable(DependencyObject element)
        {
            // CODE



            if (element == null)
            {
                return(false);
            }

            UIElement uie = element as UIElement;

            if (uie != null)
            {
                if (uie.IsVisible == false)
                {
                    return(false);
                }
            }

            if ((bool)element.GetValue(UIElement.IsEnabledProperty) == false)
            {
                return(false);
            }

            // CODE



            bool hasModifiers = false;
            BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers);
            bool focusable = (bool)element.GetValue(UIElement.FocusableProperty);

            if (!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers)
            {
                // The Focusable property was not explicitly set to anything.
                // The default value is generally false, but true in a few cases.

                if (FocusManager.GetIsFocusScope(element))
                {
                    // Focus scopes are considered focusable, even if
                    // the Focusable property is false.
                    return(true);
                }
                else if (uie != null && uie.InternalVisualParent == null)
                {
                    PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie);
                    if (presentationSource != null)
                    {
                        // A UIElements that is the root of a PresentationSource is considered focusable.
                        return(true);
                    }
                }
            }

            return(focusable);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Callback on visiting each node in the descendency
        ///     during an inheritable property change
        /// </summary>
        private static bool OnInheritablePropertyChanged(
            DependencyObject d,
            InheritablePropertyChangeInfo info,
            bool visitedViaVisualTree)
        {
            Debug.Assert(d != null, "Must have non-null current node");

            DependencyProperty dp = info.Property;
            bool inheritanceNode  = IsInheritanceNode(d, dp);

            if (inheritanceNode)
            {
                BaseValueSourceInternal  oldValueSource = BaseValueSourceInternal.Default;
                INTERNAL_PropertyStorage storage;
                if (INTERNAL_PropertyStore.TryGetInheritedPropertyStorage(d, dp, false, out storage))
                {
                    oldValueSource = storage.BaseValueSourceInternal;
                }

                // If the oldValueSource is of lower precedence than Inheritance
                // only then do we need to Invalidate the property
                if (BaseValueSourceInternal.Inherited >= oldValueSource)
                {
                    if (visitedViaVisualTree && typeof(FrameworkElement).IsInstanceOfType(d))
                    {
                        DependencyObject logicalParent = ((FrameworkElement)d).Parent;
                        if (logicalParent != null)
                        {
                            DependencyObject visualParent = VisualTreeHelper.GetParent(d);
                            if (visualParent != null && visualParent != logicalParent)
                            {
                                return(false);
                            }
                        }
                    }

                    return(d.SetInheritedValue(dp, info.NewValue, false));
                }
                else
                {
                    if (storage == null)
                    {
                        // get the storage if we didn't to it ealier.
                        INTERNAL_PropertyStore.TryGetInheritedPropertyStorage(d, dp, true, out storage);
                    }

                    // set the inherited value so that it is known if at some point,
                    // the value of higher precedence that is currently used is removed.
                    // we know that the value of the property is not changing, so we can
                    // skip the call to UpdateEffectiveValue(...)
                    storage.InheritedValue = info.NewValue;
                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        internal static bool IsFocusable(DependencyObject element)
        {
            // This should really be its own property, but it is hard to do efficiently.
            if (element == null)
            {
                return(false);
            }

            UIElement uie = element as UIElement;

            if (uie != null)
            {
                if (uie.IsVisible == false)
                {
                    return(false);
                }
            }

            if ((bool)element.GetValue(UIElement.IsEnabledProperty) == false)
            {
                return(false);
            }

            // There are too many conflicting desires for whether or not
            // an element is focusable.  We need to differentiate between
            // a false default value, and the user specifying false
            // explicitly.
            //
            bool hasModifiers = false;
            BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers);
            bool focusable = (bool)element.GetValue(UIElement.FocusableProperty);

            if (!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers)
            {
                // The Focusable property was not explicitly set to anything.
                // The default value is generally false, but true in a few cases.

                if (FocusManager.GetIsFocusScope(element))
                {
                    // Focus scopes are considered focusable, even if
                    // the Focusable property is false.
                    return(true);
                }
                else if (uie != null && uie.InternalVisualParent == null)
                {
                    PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie);
                    if (presentationSource != null)
                    {
                        // A UIElements that is the root of a PresentationSource is considered focusable.
                        return(true);
                    }
                }
            }

            return(focusable);
        }
Ejemplo n.º 6
0
        internal ValueSource(BaseValueSourceInternal source, bool isExpression, bool isAnimated, bool isCoerced, bool isCurrent)
        {
            // this cast is justified because the public BaseValueSource enum
            // values agree with the internal BaseValueSourceInternal enum values.
            _baseValueSource = (BaseValueSource)source;

            _isExpression = isExpression;
            _isAnimated   = isAnimated;
            _isCoerced    = isCoerced;
            _isCurrent    = isCurrent;
        }
Ejemplo n.º 7
0
        internal ValueSource(BaseValueSourceInternal source, bool isExpression, bool isAnimated, bool isCoerced, bool isCurrent)
        {
            // this cast is justified because the public BaseValueSource enum
            // values agree with the internal BaseValueSourceInternal enum values.
            _baseValueSource = (BaseValueSource)source;

            _isExpression = isExpression;
            _isAnimated = isAnimated;
            _isCoerced = isCoerced;
            _isCurrent = isCurrent;
        }
        // Token: 0x06000BB2 RID: 2994 RVA: 0x0002AF78 File Offset: 0x00029178
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            object syncRoot = ((ICollection)Application.Current.Resources).SyncRoot;
            object value;

            lock (syncRoot)
            {
                value = base.GetValue(valueSource);
            }
            return(value);
        }
        // Token: 0x06004A4F RID: 19023 RVA: 0x0014F910 File Offset: 0x0014DB10
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            string  textInternal = TextRangeBase.GetTextInternal(this._textContainer.Start, this._textContainer.End);
            TextBox textBox      = this._textContainer.Parent as TextBox;

            if (textBox != null)
            {
                textBox.OnDeferredTextReferenceResolved(this, textInternal);
            }
            return(textInternal);
        }
Ejemplo n.º 10
0
        /// <summary>Prepares the specified element to display the specified item. </summary>
        /// <param name="element">The element that will display the item.</param>
        /// <param name="item">The item to display.</param>
        // Token: 0x06005828 RID: 22568 RVA: 0x00186958 File Offset: 0x00184B58
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            FrameworkElement frameworkElement = element as FrameworkElement;

            if (frameworkElement != null)
            {
                Type        type        = frameworkElement.GetType();
                ResourceKey resourceKey = null;
                if (type == typeof(Button))
                {
                    resourceKey = ToolBar.ButtonStyleKey;
                }
                else if (type == typeof(ToggleButton))
                {
                    resourceKey = ToolBar.ToggleButtonStyleKey;
                }
                else if (type == typeof(Separator))
                {
                    resourceKey = ToolBar.SeparatorStyleKey;
                }
                else if (type == typeof(CheckBox))
                {
                    resourceKey = ToolBar.CheckBoxStyleKey;
                }
                else if (type == typeof(RadioButton))
                {
                    resourceKey = ToolBar.RadioButtonStyleKey;
                }
                else if (type == typeof(ComboBox))
                {
                    resourceKey = ToolBar.ComboBoxStyleKey;
                }
                else if (type == typeof(TextBox))
                {
                    resourceKey = ToolBar.TextBoxStyleKey;
                }
                else if (type == typeof(Menu))
                {
                    resourceKey = ToolBar.MenuStyleKey;
                }
                if (resourceKey != null)
                {
                    bool flag;
                    BaseValueSourceInternal valueSource = frameworkElement.GetValueSource(FrameworkElement.StyleProperty, null, out flag);
                    if (valueSource <= BaseValueSourceInternal.ImplicitReference)
                    {
                        frameworkElement.SetResourceReference(FrameworkElement.StyleProperty, resourceKey);
                    }
                    frameworkElement.DefaultStyleKey = resourceKey;
                }
            }
        }
Ejemplo n.º 11
0
        //------------------------------------------------------ 
        //
        //  Internal Methods 
        //
        //-----------------------------------------------------

        #region Internal Methods 

        // Does the real work to calculate the current TextProperty value. 
        internal override object GetValue(BaseValueSourceInternal valueSource) 
        {
            string s = TextRangeBase.GetTextInternal(_textContainer.Start, _textContainer.End); 

            TextBox tb = _textContainer.Parent as TextBox;
            if (tb != null)
            { 
                tb.OnDeferredTextReferenceResolved(this, s);
            } 
 
            return s;
        } 
Ejemplo n.º 12
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Does the real work to calculate the current TextProperty value.
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            string s = TextRangeBase.GetTextInternal(_textContainer.Start, _textContainer.End);

            TextBox tb = _textContainer.Parent as TextBox;

            if (tb != null)
            {
                tb.OnDeferredTextReferenceResolved(this, s);
            }

            return(s);
        }
Ejemplo n.º 13
0
        private static object GetActualWidth(DependencyObject d, out BaseValueSourceInternal source)
        {
            var uiElement = d as UIElement;

            if (uiElement != null && uiElement.hasWidthEverChanged)
            {
                source = BaseValueSourceInternal.Local;
                return(uiElement.RenderSize.Width);
            }
            else
            {
                source = BaseValueSourceInternal.Default;
                return(default(double));
            }
        }
Ejemplo n.º 14
0
        // Token: 0x06000CF7 RID: 3319 RVA: 0x00030004 File Offset: 0x0002E204
        internal static Collection <VisualStateGroup> GetVisualStateGroupsInternal(FrameworkElement obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            bool flag;
            BaseValueSourceInternal valueSource = obj.GetValueSource(VisualStateManager.VisualStateGroupsProperty, null, out flag);

            if (valueSource != BaseValueSourceInternal.Default)
            {
                return(obj.GetValue(VisualStateManager.VisualStateGroupsProperty) as Collection <VisualStateGroup>);
            }
            return(null);
        }
Ejemplo n.º 15
0
 internal InheritablePropertyChangeInfo(
     DependencyObject rootElement,
     DependencyProperty property,
     object oldValue,
     BaseValueSourceInternal oldValueSource,
     object newValue,
     BaseValueSourceInternal newValueSource)
 {
     _rootElement    = rootElement;
     _property       = property;
     _oldValue       = oldValue;
     _oldValueSource = oldValueSource;
     _newValue       = newValue;
     _newValueSource = newValueSource;
 }
Ejemplo n.º 16
0
        /// <summary>Prepares an item for display in the <see cref="T:System.Windows.Controls.Primitives.StatusBar" />.</summary>
        /// <param name="element">The item to display in the <see cref="T:System.Windows.Controls.Primitives.StatusBar" />.</param>
        /// <param name="item">The content of the item to display.</param>
        // Token: 0x0600601A RID: 24602 RVA: 0x001AF44C File Offset: 0x001AD64C
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            Separator separator = element as Separator;

            if (separator != null)
            {
                bool flag;
                BaseValueSourceInternal valueSource = separator.GetValueSource(FrameworkElement.StyleProperty, null, out flag);
                if (valueSource <= BaseValueSourceInternal.ImplicitReference)
                {
                    separator.SetResourceReference(FrameworkElement.StyleProperty, StatusBar.SeparatorStyleKey);
                }
                separator.DefaultStyleKey = StatusBar.SeparatorStyleKey;
            }
        }
Ejemplo n.º 17
0
        // Token: 0x060064BF RID: 25791 RVA: 0x001C40E4 File Offset: 0x001C22E4
        private static bool HasDefaultOrInheritedValueImpl(DependencyObject d, DependencyProperty dp, bool checkInherited, bool ignoreModifiers)
        {
            PropertyMetadata        metadata = dp.GetMetadata(d);
            bool                    flag;
            BaseValueSourceInternal valueSource = d.GetValueSource(dp, metadata, out flag);

            if (valueSource == BaseValueSourceInternal.Default || (checkInherited && valueSource == BaseValueSourceInternal.Inherited))
            {
                if (ignoreModifiers && (d is FrameworkElement || d is FrameworkContentElement))
                {
                    flag = false;
                }
                return(!flag);
            }
            return(false);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Prepare the element to display the item.  This may involve
        /// applying styles, setting bindings, etc.
        /// </summary>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);

            Separator separator = element as Separator;

            if (separator != null)
            {
                bool hasModifiers;
                BaseValueSourceInternal vs = separator.GetValueSource(StyleProperty, null, out hasModifiers);
                if (vs <= BaseValueSourceInternal.ImplicitReference)
                {
                    separator.SetResourceReference(StyleProperty, SeparatorStyleKey);
                }
                separator.DefaultStyleKey = SeparatorStyleKey;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Return the source of the value for the given property.
        /// </summary>
        public static ValueSource GetValueSource(DependencyObject dependencyObject, DependencyProperty dependencyProperty)
        {
            if (dependencyObject == null)
            {
                throw new ArgumentNullException(nameof(dependencyObject));
            }
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException(nameof(dependencyProperty));
            }

            dependencyObject.VerifyAccess();

            bool hasModifiers, isExpression, isAnimated, isCoerced, isCurrent;
            BaseValueSourceInternal source = dependencyObject.GetValueSource(dependencyProperty, null, out hasModifiers, out isExpression, out isAnimated, out isCoerced, out isCurrent);

            return(new ValueSource(source, isExpression, isAnimated, isCoerced, isCurrent));
        }
Ejemplo n.º 20
0
        internal static Collection <VisualStateGroup> GetVisualStateGroupsInternal(FrameworkElement obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            // We don't want to get the default value because it will create/return an empty colleciton.
            bool hasModifiers;
            BaseValueSourceInternal source = obj.GetValueSource(VisualStateGroupsProperty, null, out hasModifiers);

            if (source != BaseValueSourceInternal.Default)
            {
                return(obj.GetValue(VisualStateManager.VisualStateGroupsProperty) as Collection <VisualStateGroup>);
            }

            return(null);
        }
Ejemplo n.º 21
0
 private static void ComputeEffectiveValue(INTERNAL_PropertyStorage storage,
                                           out object effectiveValue,
                                           out BaseValueSourceInternal kind)
 {
     if (!storage.IsAnimatedOverLocal &&
         storage.LocalValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.LocalValue;
         kind           = BaseValueSourceInternal.Local;
     }
     else if (storage.IsAnimatedOverLocal &&
              storage.AnimatedValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.AnimatedValue;
         kind           = BaseValueSourceInternal.Animated;
     }
     else if (storage.ImplicitReferenceValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.ImplicitReferenceValue;
         kind           = BaseValueSourceInternal.ImplicitReference;
     }
     else if (storage.LocalStyleValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.LocalStyleValue;
         kind           = BaseValueSourceInternal.LocalStyle;
     }
     else if (storage.ThemeStyleValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.ThemeStyleValue;
         kind           = BaseValueSourceInternal.ThemeStyle;
     }
     else if (storage.InheritedValue != DependencyProperty.UnsetValue)
     {
         effectiveValue = storage.InheritedValue;
         kind           = BaseValueSourceInternal.Inherited;
     }
     else // Property default value
     {
         effectiveValue = storage.TypeMetadata.DefaultValue;
         kind           = BaseValueSourceInternal.Default;
     }
 }
Ejemplo n.º 22
0
        // Token: 0x06004DB8 RID: 19896 RVA: 0x0015EAE8 File Offset: 0x0015CCE8
        private static object CoerceCursor(DependencyObject o, object value)
        {
            GridSplitter            gridSplitter = (GridSplitter)o;
            bool                    flag;
            BaseValueSourceInternal valueSource = gridSplitter.GetValueSource(FrameworkElement.CursorProperty, null, out flag);

            if (value == null && valueSource == BaseValueSourceInternal.Default)
            {
                GridResizeDirection effectiveResizeDirection = gridSplitter.GetEffectiveResizeDirection();
                if (effectiveResizeDirection == GridResizeDirection.Columns)
                {
                    return(Cursors.SizeWE);
                }
                if (effectiveResizeDirection == GridResizeDirection.Rows)
                {
                    return(Cursors.SizeNS);
                }
            }
            return(value);
        }
Ejemplo n.º 23
0
        private static object CoerceCursor(DependencyObject o, object value)
        {
            GridSplitter splitter = (GridSplitter)o;

            bool hasModifiers;
            BaseValueSourceInternal vs = splitter.GetValueSource(CursorProperty, null, out hasModifiers);

            if (value == null && vs == BaseValueSourceInternal.Default)
            {
                switch (splitter.GetEffectiveResizeDirection())
                {
                case GridResizeDirection.Columns:
                    return(Cursors.SizeWE);

                case GridResizeDirection.Rows:
                    return(Cursors.SizeNS);
                }
            }
            return(value);
        }
Ejemplo n.º 24
0
        /// <summary>Returns a structure that reports various metadata and property system characteristics of a specified dependency property on a particular <see cref="T:System.Windows.DependencyObject" />.</summary>
        /// <param name="dependencyObject">The element that contains the <paramref name="dependencyProperty" /> to report information for.</param>
        /// <param name="dependencyProperty">The identifier for the dependency property to report information for.</param>
        /// <returns>A <see cref="T:System.Windows.ValueSource" /> structure that reports the specific information.</returns>
        // Token: 0x060003B9 RID: 953 RVA: 0x0000A968 File Offset: 0x00008B68
        public static ValueSource GetValueSource(DependencyObject dependencyObject, DependencyProperty dependencyProperty)
        {
            if (dependencyObject == null)
            {
                throw new ArgumentNullException("dependencyObject");
            }
            if (dependencyProperty == null)
            {
                throw new ArgumentNullException("dependencyProperty");
            }
            dependencyObject.VerifyAccess();
            bool flag;
            bool isExpression;
            bool isAnimated;
            bool isCoerced;
            bool isCurrent;
            BaseValueSourceInternal valueSource = dependencyObject.GetValueSource(dependencyProperty, null, out flag, out isExpression, out isAnimated, out isCoerced, out isCurrent);

            return(new ValueSource(valueSource, isExpression, isAnimated, isCoerced, isCurrent));
        }
 // Token: 0x06000BA4 RID: 2980 RVA: 0x0002ADF0 File Offset: 0x00028FF0
 internal override object GetValue(BaseValueSourceInternal valueSource)
 {
     if (this._dictionary != null)
     {
         bool   flag;
         object value = this._dictionary.GetValue(this._keyOrValue, out flag);
         if (flag)
         {
             this._keyOrValue = value;
             this.RemoveFromDictionary();
         }
         bool flag2 = valueSource == BaseValueSourceInternal.ThemeStyle || valueSource == BaseValueSourceInternal.ThemeStyleTrigger || valueSource == BaseValueSourceInternal.Style || valueSource == BaseValueSourceInternal.TemplateTrigger || valueSource == BaseValueSourceInternal.StyleTrigger || valueSource == BaseValueSourceInternal.ParentTemplate || valueSource == BaseValueSourceInternal.ParentTemplateTrigger;
         if (flag2)
         {
             StyleHelper.SealIfSealable(value);
         }
         this.OnInflated();
         return(value);
     }
     return(this._keyOrValue);
 }
        // Token: 0x06000BB5 RID: 2997 RVA: 0x0002B024 File Offset: 0x00029224
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            object themeDictionaryLock = SystemResources.ThemeDictionaryLock;
            object result;

            lock (themeDictionaryLock)
            {
                if (base.Dictionary != null)
                {
                    object key = this.Key;
                    SystemResources.IsSystemResourcesParsing = true;
                    bool   flag2;
                    object value;
                    try
                    {
                        value = base.Dictionary.GetValue(key, out flag2);
                        if (flag2)
                        {
                            this.Value      = value;
                            base.Dictionary = null;
                        }
                    }
                    finally
                    {
                        SystemResources.IsSystemResourcesParsing = false;
                    }
                    if ((key is Type || key is ResourceKey) && this._canCacheAsThemeResource && flag2)
                    {
                        SystemResources.CacheResource(key, value, false);
                    }
                    result = value;
                }
                else
                {
                    result = this.Value;
                }
            }
            return(result);
        }
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            bool flag;

            if (this.dictionary == null)
            {
                return(this.keyOrValue);
            }
            object value = this.dictionary.GetValue(this.keyOrValue, out flag);

            if (!this.CheckIfShared || flag)
            {
                this.keyOrValue = value;
                this.RemoveFromDictionary();
            }
            if (valueSource == BaseValueSourceInternal.ThemeStyle || valueSource == BaseValueSourceInternal.ThemeStyleTrigger || valueSource == BaseValueSourceInternal.Style || valueSource == BaseValueSourceInternal.TemplateTrigger || valueSource == BaseValueSourceInternal.StyleTrigger || valueSource == BaseValueSourceInternal.ParentTemplate || valueSource == BaseValueSourceInternal.ParentTemplateTrigger)
            {
                StyleHelper.SealIfSealable(value);
            }
            this.OnInflated();
            return(value);
        }
Ejemplo n.º 28
0
 private static void ComputeEffectiveValue(INTERNAL_PropertyStorage storage,
                                           out object effectiveValue,
                                           out BaseValueSourceInternal kind)
 {
     /*if ((effectiveValue = storage.VisualStateValue) != INTERNAL_NoValue.NoValue)
      * {
      *  kind = KindOfValue.VisualState;
      * }
      * else */
     if (!storage.IsAnimatedOverLocal &&
         (effectiveValue = storage.LocalValue) != DependencyProperty.UnsetValue)
     {
         kind = BaseValueSourceInternal.Local;
     }
     else if (storage.IsAnimatedOverLocal &&
              (effectiveValue = storage.AnimatedValue) != DependencyProperty.UnsetValue)
     {
         kind = BaseValueSourceInternal.Animated;
     }
     else if ((effectiveValue = storage.LocalStyleValue) != DependencyProperty.UnsetValue)
     {
         kind = BaseValueSourceInternal.LocalStyle;
     }
     else if ((effectiveValue = storage.ImplicitStyleValue) != DependencyProperty.UnsetValue)
     {
         kind = BaseValueSourceInternal.ImplicitStyle;
     }
     else if ((effectiveValue = storage.InheritedValue) != DependencyProperty.UnsetValue)
     {
         kind = BaseValueSourceInternal.Inherited;
     }
     else // Property default value
     {
         effectiveValue = storage.TypeMetadata.DefaultValue;
         kind           = BaseValueSourceInternal.Default;
     }
 }
Ejemplo n.º 29
0
 internal override object GetValue(BaseValueSourceInternal valueSource)
 { 
     return Value;
 }
Ejemplo n.º 30
0
        internal override object GetValue(BaseValueSourceInternal valueSource) 
        {
            lock (SystemResources.ThemeDictionaryLock)
            {
                // If the value cache is invalid fetch the value from 
                // the dictionary else just retun the cached value
                if (Dictionary != null) 
                { 
                    bool canCache;
                    object key = Key; 
                    object value;

                    SystemResources.IsSystemResourcesParsing = true;
 
                    try
                    { 
                        value = Dictionary.GetValue(key, out canCache); 
                        if (canCache)
                        { 
                            // Note that we are replacing the _keyorValue field
                            // with the value and nuking the _dictionary field.
                            Value = value;
                            Dictionary = null; 
                        }
                    } 
                    finally 
                    {
                        SystemResources.IsSystemResourcesParsing = false; 
                    }

                    // Only cache keys that would be located by FindResourceInternal
                    if ((key is Type || key is ResourceKey) && canCache) 
                    {
                        SystemResources.CacheResource(key, value, false /*isTraceEnabled*/); 
                    } 

                    return value; 
                }

                return Value;
            } 
        }
Ejemplo n.º 31
0
 internal EffectiveValueEntry(DependencyProperty dp, BaseValueSourceInternal valueSource)
 {
     _propertyIndex = (short)dp.GlobalIndex;
     _value         = DependencyProperty.UnsetValue;
     _source        = (FullValueSource)valueSource;
 }
Ejemplo n.º 32
0
 internal override object GetValue(BaseValueSourceInternal valueSource)
 {
     return _sourceMetadata.GetDefaultValue(_sourceObject, _sourceProperty);
 }
Ejemplo n.º 33
0
        private static void UpdateEffectiveValue(INTERNAL_PropertyStorage storage,
                                                 object newValue,
                                                 BaseValueSourceInternal newValueSource,
                                                 bool coerceWithCurrentValue,
                                                 bool coerceValue,
                                                 bool clearValue,
                                                 bool propagateChanges)
        {
            global::System.Diagnostics.Debug.Assert((coerceWithCurrentValue == coerceValue && !coerceValue) || coerceValue != coerceWithCurrentValue);

            bool isCoerceOperation = coerceValue || coerceWithCurrentValue;
            BaseValueSourceInternal oldBaseValueSource = storage.BaseValueSourceInternal;

            object            oldValue;
            BindingExpression currentExpr = null;

            // Compute new value
            object effectiveValue;
            BaseValueSourceInternal effectiveValueKind;

            if (isCoerceOperation)
            {
                // Source and base value are unchanged during coercion operation
                effectiveValue     = newValue;
                effectiveValueKind = oldBaseValueSource;

                // Get old value before it gets overriden
                oldValue = GetEffectiveValue(storage);
            }
            else
            {
                ComputeEffectiveValue(storage, out effectiveValue, out effectiveValueKind);

                // Check for early exit if effective value is not impacted (if we are doing
                // a coerce operation, we have to go through the update process)
                if (effectiveValueKind == oldBaseValueSource &&
                    newValueSource < effectiveValueKind)
                {
                    // value source remains the same.
                    // Exit if the newly set value is of lower precedence than the effective value.
                    return;
                }

                // Get old value before it gets overriden
                oldValue = GetEffectiveValue(storage);

                currentExpr = (storage.IsExpression || storage.IsExpressionFromStyle) ? storage.ModifiedValue.BaseValue as BindingExpression : null;

#if USEASSERT
                // If the current base value is a BindingExpression, it should have been detached by now
                // Or is the same instance as 'effectiveValue' (this occurs when we update a property bound to a
                // BindingExpression)
                global::System.Diagnostics.Debug.Assert(currentExpr == null ||
                                                        !currentExpr.IsAttached ||
                                                        object.ReferenceEquals(currentExpr, effectiveValue), "Binding expression should be detached.");
#endif

                storage.ResetValue();

                // Update the base value source
                storage.BaseValueSourceInternal = effectiveValueKind;
            }

            object computedValue;

            if (!isCoerceOperation)
            {
                BindingExpression newExpr = effectiveValue as BindingExpression;
                if (newExpr == null)
                {
                    computedValue = storage.Property.PropertyType == typeof(string)
                                    ? effectiveValue?.ToString()
                                    : effectiveValue;
                    storage.Value = computedValue;
                }
                else
                {
#if USEASSERT
                    global::System.Diagnostics.Debug.Assert(effectiveValueKind == BaseValueSourceInternal.Local || effectiveValueKind == BaseValueSourceInternal.LocalStyle);
#endif

                    // If the new BindingExpression is the same as the current one,
                    // the BindingExpression is already attached
                    bool isNewBinding = !object.ReferenceEquals(currentExpr, newExpr);
                    if (isNewBinding)
                    {
                        if (newExpr.IsAttached)
                        {
                            throw new InvalidOperationException(string.Format("Cannot attach an instance of '{0}' multiple times", typeof(BindingExpression)));
                        }
                        newExpr.OnAttached(storage.Owner);
                        storage.Value = newExpr; // Set the new base value
                    }

                    if (effectiveValueKind == BaseValueSourceInternal.Local)
                    {
                        storage.SetExpressionValue(storage.TypeMetadata.DefaultValue, newExpr);
                    }
                    else
                    {
                        storage.SetExpressionFromStyleValue(storage.TypeMetadata.DefaultValue, newExpr);
                    }

                    // 1- 'isNewBinding == true' means that we are attaching a new BindingExpression.
                    // 2- 'newValue is BindingExpression == true' means that we are re-evaluating a BindingEpression
                    // (usually by calling RefreshBindingExpressionCommon)
                    // 3- Otherwise we are trying to change the value of a TwoWay binding.
                    // In that case we have to preserve the BindingExpression (this is not the case if the first two
                    // situations), hence the following line :
                    computedValue = isNewBinding || newValue is BindingExpression?newExpr.GetValue(storage.Property, storage.Owner.GetType())
                                        : newValue;

                    computedValue = storage.Property.PropertyType == typeof(string)
                                    ? computedValue?.ToString()
                                    : computedValue;
                    storage.ModifiedValue.ExpressionValue = computedValue;
                }
            }
            else
            {
                computedValue = coerceWithCurrentValue ? newValue : GetCoercionBaseValue(storage);
                if (coerceValue)
                {
                    storage.ResetCoercedValue();
                }
            }

            // Coerce to current value
            if (coerceWithCurrentValue)
            {
                object baseValue = GetCoercionBaseValue(storage);
                ProcessCoerceValue(storage,
                                   ref computedValue,
                                   oldValue,
                                   baseValue,
                                   true);
            }

            // Coerce Value
            // We don't want to coerce the value if it's being reset to the property's default value
            if (storage.TypeMetadata.CoerceValueCallback != null && !(clearValue && storage.FullValueSource == (FullValueSource)BaseValueSourceInternal.Default))
            {
                object baseValue = GetCoercionBaseValue(storage);
                ProcessCoerceValue(storage,
                                   ref computedValue,
                                   oldValue,
                                   baseValue,
                                   false);
            }

            // Reset old value inheritance context
            if (oldBaseValueSource == BaseValueSourceInternal.Local)
            {
                // Notes:
                // - Inheritance context is only handled by local value
                // - We use null instead of the actual DependencyProperty
                // as the parameter is ignored in the current implentation.
                storage.Owner.RemoveSelfAsInheritanceContext(oldValue, null /*storage.Property*/);
            }

            // Set new value inheritance context
            if (effectiveValueKind == BaseValueSourceInternal.Local)
            {
                // Check above
                storage.Owner.ProvideSelfAsInheritanceContext(computedValue, null /*storage.Property*/);
            }

            if (!ArePropertiesEqual(oldValue, computedValue, storage.Property.PropertyType))
            {
                // Raise the PropertyChanged event
                if (!storage.TypeMetadata.Inherits || ShouldRaisePropertyChanged(storage))
                {
                    OnPropertyChanged(storage, oldValue, computedValue);
                }

                // Propagate to children if property is inherited
                if (storage.TypeMetadata.Inherits && propagateChanges)
                {
                    CascadeInheritedPropertyToChildren(storage, computedValue);
                }
            }

            // Update the source of the Binding, in case the previous value of a property was a Binding and the Mode was "TwoWay":
            if (currentExpr != null && currentExpr.ParentBinding.Mode == BindingMode.TwoWay) //note: we know that oldBindingExpression.IsUpdating is false because oldBindingExpression is only set in that case (otherwise, it is null).
            {
                currentExpr.TryUpdateSourceObject(computedValue);
            }
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Deferences a property value on demand.
        internal abstract object GetValue(BaseValueSourceInternal valueSource);
Ejemplo n.º 35
0
 private static object GetIsVisible(DependencyObject d, out BaseValueSourceInternal source)
 {
     source = BaseValueSourceInternal.Local;
     return ((UIElement3D)d).IsVisible ? BooleanBoxes.TrueBox : BooleanBoxes.FalseBox;
 }
Ejemplo n.º 36
0
 internal EffectiveValueEntry(DependencyProperty dp, BaseValueSourceInternal valueSource)
 {
     _propertyIndex = (short) dp.GlobalIndex;
     _value = DependencyProperty.UnsetValue;
     _source = (FullValueSource) valueSource;
 }
        //------------------------------------------------------ 
        //
        //  Internal Methods 
        //
        //-----------------------------------------------------

        #region Internal Methods 

        // Does the real work to calculate the current SelectedIndexProperty value. 
        internal override object GetValue(BaseValueSourceInternal valueSource) 
        {
            return _selector.InternalSelectedIndex; 
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Does the real work to calculate the current TextProperty value.
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            return TextRangeBase.GetTextInternal(_run.ContentStart, _run.ContentEnd);
        }
 internal override object GetValue(BaseValueSourceInternal valueSource)
 {
     return(_sourceMetadata.GetDefaultValue(_sourceObject, _sourceProperty));
 }
Ejemplo n.º 40
0
 private static object GetActualWidth(DependencyObject d, out BaseValueSourceInternal source)
 {
     FrameworkElement frameworkElement = (FrameworkElement) d;
       if (frameworkElement.HasWidthEverChanged)
       {
     source = BaseValueSourceInternal.Local;
     return (object) frameworkElement.RenderSize.Width;
       }
       else
       {
     source = BaseValueSourceInternal.Default;
     return (object) 0.0;
       }
 }
Ejemplo n.º 41
0
        [FriendAccessAllowed] // Built into Base, also used by Core and Framework.
        internal void SetEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, int targetIndex, PropertyMetadata metadata, object value, BaseValueSourceInternal valueSource) 
        { 
            Debug.Assert(value != DependencyProperty.UnsetValue, "Value to be set cannot be UnsetValue");
            Debug.Assert(valueSource != BaseValueSourceInternal.Unknown, "ValueSource cannot be Unknown"); 

            // For thread-safety, sealed DOs can't modify _effectiveValues.
            Debug.Assert(!DO_Sealed, "A Sealed DO cannot be modified");
 
            if (metadata != null &&
                metadata.IsInherited && 
                valueSource != BaseValueSourceInternal.Inherited && 
                !IsSelfInheritanceParent)
            { 
                SetIsSelfInheritanceParent();
                entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);
            }
 
            EffectiveValueEntry entry;
            if (entryIndex.Found) 
            { 
                entry = _effectiveValues[entryIndex.Index];
            } 
            else
            {
                entry = new EffectiveValueEntry();
                entry.PropertyIndex = targetIndex; 
                InsertEntry(entry, entryIndex.Index);
                if (metadata != null && metadata.IsInherited) 
                { 
                    InheritableEffectiveValuesCount++;
                } 
            }

            bool hasExpressionMarker = (value == ExpressionInAlternativeStore);
 
            if (!hasExpressionMarker &&
                entry.HasExpressionMarker && 
                (valueSource == BaseValueSourceInternal.ThemeStyle || 
                 valueSource == BaseValueSourceInternal.ThemeStyleTrigger ||
                 valueSource == BaseValueSourceInternal.Style || 
                 valueSource == BaseValueSourceInternal.TemplateTrigger ||
                 valueSource == BaseValueSourceInternal.StyleTrigger ||
                 valueSource == BaseValueSourceInternal.ParentTemplate ||
                 valueSource == BaseValueSourceInternal.ParentTemplateTrigger)) 
            {
                entry.BaseValueSourceInternal = valueSource; 
                entry.SetExpressionValue(value, ExpressionInAlternativeStore); 
                entry.ResetAnimatedValue();
                entry.ResetCoercedValue(); 
            }
            else if (entry.IsExpression && entry.ModifiedValue.ExpressionValue == Expression.NoValue)
            {
                // we now have a value for an expression that is "hiding" - save it 
                // as the expression value
                entry.SetExpressionValue(value, entry.ModifiedValue.BaseValue); 
            } 
            else
            { 
                Debug.Assert(entry.BaseValueSourceInternal != BaseValueSourceInternal.Local || valueSource == BaseValueSourceInternal.Local,
                    "No one but another local value can stomp over an existing local value. The only way is to clear the entry");

                entry.BaseValueSourceInternal = valueSource; 
                entry.ResetValue(value, hasExpressionMarker);
            } 
 
            Debug.Assert(dp == null || (dp.GlobalIndex == entry.PropertyIndex), "EffectiveValueEntry & DependencyProperty do not match");
            _effectiveValues[entryIndex.Index] = entry; 
        }
Ejemplo n.º 42
0
        internal override object GetValue(BaseValueSourceInternal valueSource)
        {
            // If the _value cache is invalid fetch the value from
            // the dictionary else just retun the cached value 
            if (_dictionary != null)
            { 
                bool canCache; 
                object value  = _dictionary.GetValue(_keyOrValue, out canCache);
                if (canCache) 
                {
                    // Note that we are replacing the _keyorValue field
                    // with the value and nuking the _dictionary field.
                    _keyOrValue = value; 
                    RemoveFromDictionary();
                } 
 
                // Freeze if this value originated from a style or template
                bool freezeIfPossible = 
                    valueSource == BaseValueSourceInternal.ThemeStyle ||
                    valueSource == BaseValueSourceInternal.ThemeStyleTrigger ||
                    valueSource == BaseValueSourceInternal.Style ||
                    valueSource == BaseValueSourceInternal.TemplateTrigger || 
                    valueSource == BaseValueSourceInternal.StyleTrigger ||
                    valueSource == BaseValueSourceInternal.ParentTemplate || 
                    valueSource == BaseValueSourceInternal.ParentTemplateTrigger; 

                // This is to freeze values produced by deferred 
                // references within styles and templates
                if (freezeIfPossible)
                {
                    StyleHelper.SealIfSealable(value); 
                }
 
                // tell any listeners (e.g. ResourceReferenceExpressions) 
                // that the value has been inflated
                OnInflated(); 

                return value;
            }
 
            return _keyOrValue;
        } 
Ejemplo n.º 43
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Deferences a property value on demand.
        internal abstract object GetValue(BaseValueSourceInternal valueSource);
Ejemplo n.º 44
0
 internal override object GetValue(BaseValueSourceInternal valueSource)
 { 
     lock (((ICollection)Application.Current.Resources).SyncRoot)
     { 
         return base.GetValue(valueSource); 
     }
 } 
Ejemplo n.º 45
0
 internal override object GetValue(BaseValueSourceInternal valueSource)
 {
     bool flag;
     if (this.dictionary == null)
     {
         return this.keyOrValue;
     }
     object value = this.dictionary.GetValue(this.keyOrValue, out flag);
     if (!this.CheckIfShared || flag)
     {
         this.keyOrValue = value;
         this.RemoveFromDictionary();
     }
     if (valueSource == BaseValueSourceInternal.ThemeStyle || valueSource == BaseValueSourceInternal.ThemeStyleTrigger || valueSource == BaseValueSourceInternal.Style || valueSource == BaseValueSourceInternal.TemplateTrigger || valueSource == BaseValueSourceInternal.StyleTrigger || valueSource == BaseValueSourceInternal.ParentTemplate || valueSource == BaseValueSourceInternal.ParentTemplateTrigger)
     {
         StyleHelper.SealIfSealable(value);
     }
     this.OnInflated();
     return value;
 }
Ejemplo n.º 46
0
 private static object GetActualHeight(DependencyObject d, out BaseValueSourceInternal source)
 { 
     FrameworkElement fe = (FrameworkElement) d;
     if (fe.HasHeightEverChanged)
     {
         source = BaseValueSourceInternal.Local; 
         return fe.RenderSize.Height;
     } 
     else 
     {
         source = BaseValueSourceInternal.Default; 
         return 0d;
     }
 }