Exemplo n.º 1
0
 // Token: 0x06000361 RID: 865 RVA: 0x00009AD8 File Offset: 0x00007CD8
 internal void Seal(ValueLookupType type)
 {
     this._sealed = true;
     for (int i = 0; i < base.Count; i++)
     {
         base[i].Seal(type);
     }
 }
Exemplo n.º 2
0
        internal void Seal(ValueLookupType type)
        {
            _sealed = true;

            // Seal all the conditions
            for (int i = 0; i < Count; i++)
            {
                this[i].Seal(type);
            }
        }
Exemplo n.º 3
0
 // Token: 0x06000357 RID: 855 RVA: 0x000097C0 File Offset: 0x000079C0
 internal void Seal(ValueLookupType type)
 {
     if (this._sealed)
     {
         return;
     }
     this._sealed = true;
     if (this._property != null && this._binding != null)
     {
         throw new InvalidOperationException(SR.Get("ConditionCannotUseBothPropertyAndBinding"));
     }
     if (type - ValueLookupType.Trigger > 1)
     {
         if (type - ValueLookupType.DataTrigger > 1)
         {
             throw new InvalidOperationException(SR.Get("UnexpectedValueTypeForCondition", new object[]
             {
                 type
             }));
         }
         if (this._binding == null)
         {
             throw new InvalidOperationException(SR.Get("NullPropertyIllegal", new object[]
             {
                 "Binding"
             }));
         }
     }
     else
     {
         if (this._property == null)
         {
             throw new InvalidOperationException(SR.Get("NullPropertyIllegal", new object[]
             {
                 "Property"
             }));
         }
         if (!this._property.IsValidValue(this._value))
         {
             throw new InvalidOperationException(SR.Get("InvalidPropertyValue", new object[]
             {
                 this._value,
                 this._property.Name
             }));
         }
     }
     StyleHelper.SealIfSealable(this._value);
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Seal the condition so that it can no longer be modified
        /// </summary>
        internal void Seal(ValueLookupType type)
        {
            if (_sealed)
            {
                return;
            }

            _sealed = true;

            // Ensure valid condition
            if (_property != null && _binding != null)
            {
                throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding));
            }

            switch (type)
            {
            case ValueLookupType.Trigger:
            case ValueLookupType.PropertyTriggerResource:
                if (_property == null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Property"));
                }

                if (!_property.IsValidValue(_value))
                {
                    throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, _value, _property.Name));
                }
                break;

            case ValueLookupType.DataTrigger:
            case ValueLookupType.DataTriggerResource:
                if (_binding == null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Binding"));
                }
                break;

            default:
                throw new InvalidOperationException(SR.Get(SRID.UnexpectedValueTypeForCondition, type));
            }

            // Freeze the condition value
            StyleHelper.SealIfSealable(_value);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Seal the condition so that it can no longer be modified
        /// </summary>
        internal void Seal(ValueLookupType type)
        {
            if (_sealed)
            {
                return;
            }

            _sealed = true;

            // Ensure valid condition
            if (_property != null && _binding != null)
                throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding));

            switch (type)
            {
                case ValueLookupType.Trigger:
                case ValueLookupType.PropertyTriggerResource:
                    if (_property == null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Property"));
                    }

                    if (!_property.IsValidValue(_value))
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, _value, _property.Name));
                    }
                    break;

                case ValueLookupType.DataTrigger:
                case ValueLookupType.DataTriggerResource:
                    if (_binding == null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Binding"));
                    }
                    break;

                default:
                    throw new InvalidOperationException(SR.Get(SRID.UnexpectedValueTypeForCondition, type));
            }

            // Freeze the condition value
            StyleHelper.SealIfSealable(_value);
        }
Exemplo n.º 6
0
        //
        //  This method
        //  1. Computes the property value given the ChildLookupValue list for it
        //
        private static object GetChildValueHelper(
            UncommonField<HybridDictionary[]>       dataField,
            ref ItemStructList<ChildValueLookup>    valueLookupList,
            DependencyProperty                      dp,
            DependencyObject                        container,
            FrameworkObject                         child,
            int                                     childIndex,
            bool                                    styleLookup,
            ref EffectiveValueEntry                 entry,
            out ValueLookupType                     sourceType,
            FrameworkElementFactory                 templateRoot)
        {
            Debug.Assert(child.IsValid, "child should either be an FE or an FCE");

            object value = DependencyProperty.UnsetValue;
            sourceType = ValueLookupType.Simple;

            // Walk list backwards since highest priority lookup items are inserted last
            for (int i = valueLookupList.Count - 1; i >= 0; i--)
            {
                sourceType = valueLookupList.List[i].LookupType;

                // Lookup logic is determined by lookup type. "Trigger"
                // is misleading right now because today it's also being used
                // for Storyboard timeline lookups.
                switch (valueLookupList.List[i].LookupType)
                {
                case ValueLookupType.Simple:
                    {
                        // Simple value
                        value = valueLookupList.List[i].Value;
                    }
                    break;

                case ValueLookupType.Trigger:
                case ValueLookupType.PropertyTriggerResource:
                case ValueLookupType.DataTrigger:
                case ValueLookupType.DataTriggerResource:
                    {
                        // Conditional value based on Container state
                        bool triggerMatch = true;

                        if( valueLookupList.List[i].Conditions != null )
                        {
                            // Check whether the trigger applies.  All conditions must match,
                            // so the loop can terminate as soon as it finds a condition
                            // that doesn't match.
                            for (int j = 0; triggerMatch && j < valueLookupList.List[i].Conditions.Length; j++)
                            {
                                object state;

                                switch (valueLookupList.List[i].LookupType)
                                {
                                case ValueLookupType.Trigger:
                                case ValueLookupType.PropertyTriggerResource:
                                    // Find the source node
                                    DependencyObject sourceNode;
                                    int sourceChildIndex = valueLookupList.List[i].Conditions[j].SourceChildIndex;
                                    if (sourceChildIndex == 0)
                                    {
                                        sourceNode = container;
                                    }
                                    else
                                    {
                                        sourceNode = StyleHelper.GetChild(container, sourceChildIndex);
                                    }

                                    // Note that the sourceNode could be null when the source
                                    // property for this trigger is on a node that hasn't been
                                    // instantiated yet.
                                    DependencyProperty sourceProperty = valueLookupList.List[i].Conditions[j].Property;
                                    if (sourceNode != null)
                                    {
                                        state = sourceNode.GetValue(sourceProperty);
                                    }
                                    else
                                    {
                                        Type sourceNodeType;

                                        if( templateRoot != null )
                                        {
                                            sourceNodeType = FindFEF(templateRoot, sourceChildIndex).Type;
                                        }
                                        else
                                        {
                                            sourceNodeType = (container as FrameworkElement).TemplateInternal.ChildTypeFromChildIndex[sourceChildIndex];
                                        }

                                        state = sourceProperty.GetDefaultValue(sourceNodeType);
                                    }

                                    triggerMatch = valueLookupList.List[i].Conditions[j].Match(state);

                                    break;

                                case ValueLookupType.DataTrigger:
                                case ValueLookupType.DataTriggerResource:
                                default:    // this cannot happen - but make the compiler happy

                                    state = GetDataTriggerValue(dataField, container, valueLookupList.List[i].Conditions[j].Binding);
                                    triggerMatch = valueLookupList.List[i].Conditions[j].ConvertAndMatch(state);

                                    break;
                                }
                            }
                        }

                        if (triggerMatch)
                        {
                            // Conditionals matched, use the value

                            if (valueLookupList.List[i].LookupType == ValueLookupType.PropertyTriggerResource ||
                                valueLookupList.List[i].LookupType == ValueLookupType.DataTriggerResource)
                            {
                                // Resource lookup
                                object source;
                                value = FrameworkElement.FindResourceInternal(child.FE,
                                                                              child.FCE,
                                                                              dp,
                                                                              valueLookupList.List[i].Value,  // resourceKey
                                                                              null,  // unlinkedParent
                                                                              true,  // allowDeferredResourceReference
                                                                              false, // mustReturnDeferredResourceReference
                                                                              null,  // boundaryElement
                                                                              false, // disableThrowOnResourceNotFound
                                                                              out source);

                                // Try to freeze the value
                                SealIfSealable(value);
                            }
                            else
                            {
                                value = valueLookupList.List[i].Value;
                            }
                        }
                    }
                    break;

                case ValueLookupType.TemplateBinding:
                    {
                        TemplateBindingExtension templateBinding = (TemplateBindingExtension)valueLookupList.List[i].Value;
                        DependencyProperty sourceProperty = templateBinding.Property;

                        // Direct binding of Child property to Container
                        value = container.GetValue(sourceProperty);

                        // Apply the converter, if any
                        if (templateBinding.Converter != null)
                        {
                            DependencyProperty targetProperty = valueLookupList.List[i].Property;
                            System.Globalization.CultureInfo culture = child.Language.GetCompatibleCulture();

                            value = templateBinding.Converter.Convert(
                                                value,
                                                targetProperty.PropertyType,
                                                templateBinding.ConverterParameter,
                                                culture);
                        }

                        // if the binding returns an invalid value, fallback to default value
                        if ((value != DependencyProperty.UnsetValue) && !dp.IsValidValue(value))
                        {
                            value = DependencyProperty.UnsetValue;
                        }
                    }
                    break;

                case ValueLookupType.Resource:
                    {
                        // Resource lookup
                        object source;
                        value = FrameworkElement.FindResourceInternal(
                                        child.FE,
                                        child.FCE,
                                        dp,
                                        valueLookupList.List[i].Value,  // resourceKey
                                        null,  // unlinkedParent
                                        true,  // allowDeferredResourceReference
                                        false, // mustReturnDeferredResourceReference
                                        null,  // boundaryElement
                                        false, // disableThrowOnResourceNotFound
                                        out source);

                        // Try to freeze the value
                        SealIfSealable(value);
                    }
                    break;
                }

                // See if value needs per-instance storage
                if (value != DependencyProperty.UnsetValue)
                {
                    entry.Value = value;
                    // When the value requires per-instance storage (and comes from this style),
                    // get the real value from per-instance data.
                    switch (valueLookupList.List[i].LookupType)
                    {
                    case ValueLookupType.Simple:
                    case ValueLookupType.Trigger:
                    case ValueLookupType.DataTrigger:
                        {
                            MarkupExtension me;
                            Freezable freezable;

                            if ((me = value as MarkupExtension) != null)
                            {
                                value = GetInstanceValue(
                                                dataField,
                                                container,
                                                child.FE,
                                                child.FCE,
                                                childIndex,
                                                valueLookupList.List[i].Property,
                                                i,
                                                ref entry);
                            }
                            else if ((freezable = value as Freezable) != null && !freezable.IsFrozen)
                            {
                                value = GetInstanceValue(
                                                dataField,
                                                container,
                                                child.FE,
                                                child.FCE,
                                                childIndex,
                                                valueLookupList.List[i].Property,
                                                i,
                                                ref entry);
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }

                if (value != DependencyProperty.UnsetValue)
                {
                    // Found a value, break out of the for() loop.
                    break;
                }
            }

            return value;
        }
Exemplo n.º 7
0
        //  ===========================================================================
        //  These methods are invoked when a Property
        //  value is fetched from a Style/Template
        //  ===========================================================================

        #region GetValueMethods

        //
        //  This method
        //  1. Computes the value of a template child
        //     (Index is '0' when the styled container is asking)
        //
        internal static object GetChildValue(
            UncommonField<HybridDictionary[]>   dataField,
            DependencyObject                    container,
            int                                 childIndex,
            FrameworkObject                     child,
            DependencyProperty                  dp,
            ref FrugalStructList<ChildRecord>   childRecordFromChildIndex,
            ref EffectiveValueEntry             entry,
            out ValueLookupType                 sourceType,
            FrameworkElementFactory             templateRoot)
        {
            object value = DependencyProperty.UnsetValue;
            sourceType = ValueLookupType.Simple;

            // Check if this Child Index is represented in given data-structure
            if ((0 <= childIndex) && (childIndex < childRecordFromChildIndex.Count))
            {
                // Fetch the childRecord for the given childIndex
                ChildRecord childRecord = childRecordFromChildIndex[childIndex];

                // Check if this Property is represented in the childRecord
                int mapIndex = childRecord.ValueLookupListFromProperty.Search(dp.GlobalIndex);
                if (mapIndex >= 0)
                {
                    if (childRecord.ValueLookupListFromProperty.Entries[mapIndex].Value.Count > 0)
                    {
                        // Child Index/Property are both represented in this style/template,
                        // continue with value computation

                        // Pass into helper so ValueLookup struct can be accessed by ref
                        value = GetChildValueHelper(
                            dataField,
                            ref childRecord.ValueLookupListFromProperty.Entries[mapIndex].Value,
                            dp,
                            container,
                            child,
                            childIndex,
                            true,
                            ref entry,
                            out sourceType,
                            templateRoot);
                    }
                }
            }

            return value;
        }