Example #1
0
        /// <summary> 
        /// Handle property node when within a Triggers section.  Return true if this
        /// node is fully handled and needs no further processing.
        /// </summary>
        private bool WritePropertyForTriggers(XamlPropertyNode xamlPropertyNode) 
        {
            if (_inSetterDepth >= 0) 
            { 
                if (xamlPropertyNode.PropName == XamlTemplateSerializer.SetterValueAttributeName)
                { 
                    _setterOrTriggerValueNode = xamlPropertyNode;
                    // Delay writing out the Value attribute until WriteEndAttributes if this is a
                    // normal property node.  If this is a property node that was created from complex
                    // syntax, then the WriteEndAttributes has already occurred, so process the 
                    // node now.
                    if (xamlPropertyNode.ComplexAsSimple) 
                    { 
                        ProcessPropertyValueNode();
                    } 
                    return true;
                }
                else if (xamlPropertyNode.PropName == XamlTemplateSerializer.SetterPropertyAttributeName)
                { 
                    // Property names should be trimmed since whitespace is not significant
                    // and can affect name resolution (See Windows bug 1035621) 
                    xamlPropertyNode.SetValue(xamlPropertyNode.Value.Trim()); 
                    _setterOrTriggerPropertyNode = xamlPropertyNode;
 
                    // return now as Setter.TargetName might not have been set yet and we need that for resolving
                    // the property name. So this is done in WriteEndattributes.
                    return true;
                } 
                else if (xamlPropertyNode.PropName == XamlTemplateSerializer.SetterTargetAttributeName)
                { 
                    _setterTargetNameOrConditionSourceName = xamlPropertyNode.Value; 
                }
            } 
            else
            {
                if (xamlPropertyNode.PropName == XamlTemplateSerializer.PropertyTriggerValuePropertyName)
                { 
                    // DataTrigger doesn't have a "Property" property so value has to be written directly.
                    // This check filters out if "Property" was actually set vs. not present at all for 
                    // other Triggers. 
                    Type t = (Type)_elementTypeStack.Peek();
                    if (!KnownTypes.Types[(int)KnownElements.DataTrigger].IsAssignableFrom(t)) 
                    {
                        _setterOrTriggerValueNode = xamlPropertyNode;
                        // Delay writing out the Value attribute until WriteEndAttributes if this is a
                        // normal property node.  If this is a property node that was created from complex 
                        // syntax, then the WriteEndAttributes has already occurred, so process the
                        // node now. 
                        if (xamlPropertyNode.ComplexAsSimple) 
                        {
                            ProcessPropertyValueNode(); 
                        }
                        return true;
                    }
                } 
                else if (xamlPropertyNode.PropName == XamlTemplateSerializer.PropertyTriggerPropertyName)
                { 
                    // Property names should be trimmed since whitespace is not significant 
                    // and can affect name resolution (See Windows bug 1035621)
                    xamlPropertyNode.SetValue(xamlPropertyNode.Value.Trim()); 
                    _setterOrTriggerPropertyNode = xamlPropertyNode;

                    // return now as Trigger.SourceName might not have been set yet and we need that for resolving
                    // the property name. So this is done in WriteEndattributes. 
                    return true;
                } 
                else if (xamlPropertyNode.PropName == XamlTemplateSerializer.PropertyTriggerSourceName) 
                {
                    _setterTargetNameOrConditionSourceName = xamlPropertyNode.Value; 
                }
            }

            return false; 
        }
Example #2
0
        /// <summary> 
        /// Write a Property, which has the form in markup of property="value". 
        /// </summary>
        public override void WriteProperty(XamlPropertyNode xamlPropertyNode) 
        {
            StyleMode mode = _styleModeStack.Mode;

            Debug.Assert (mode != StyleMode.Base || xamlPropertyNode.PropName != XamlStyleSerializer.TargetTypePropertyName, 
                          "TargetType should be handled by WritePropertyWithType");
 
            if (mode == StyleMode.TargetTypeProperty && 
                xamlPropertyNode.PropName == "TypeName")
            { 
                // Remember the TargetType name so that the event setter parsing could use it
                // to resolve non-qualified event names
                _styleTargetTypeString = xamlPropertyNode.Value;
            } 

            // When compiling, native DependencyProperties may not have a static setter, 
            // so all we can resolve is the associated PropertyInfo.  In this case, we 
            // will check to see if there is a static field named PropName+Property and
            // assume that this will be a DependencyProperty that can be resolved at 
            // runtime.  If there is no property with this naming pattern, then it can't
            // resolve at runtime, so complain now.  Note that this is only done in the
            // compile case, since a cheaper check is done in the StyleBamlRecordReader
            // for the xaml-to-tree case. 
            if (mode == StyleMode.Setters ||
                mode == StyleMode.TriggerBase) 
            { 
                if (_inSetterDepth >= 0 && !_inEventSetter)
                { 
                    // Trigger Setters processed here.
                    if (xamlPropertyNode.PropName == XamlStyleSerializer.SetterValueAttributeName)
                    {
                        _setterOrTriggerValueNode = xamlPropertyNode; 
                        // Delay writing out the Value attribute until WriteEndAttributes if this is a
                        // normal property node.  If this is a property node that was created from complex 
                        // syntax, then the WriteEndAttributes has already occurred, so process the 
                        // node now.
                        if (xamlPropertyNode.ComplexAsSimple) 
                        {
                            ProcessPropertyValueNode();
                        }
 
                        return;
                    } 
                    else if (xamlPropertyNode.PropName == XamlStyleSerializer.SetterPropertyAttributeName) 
                    {
                        // Property names should be trimmed since whitespace is not significant 
                        // and can affect name resolution (See Windows bug 1035621)
                        xamlPropertyNode.SetValue(xamlPropertyNode.Value.Trim());
                        _setterOrTriggerPropertyInfo = GetDependencyPropertyInfo(xamlPropertyNode);
                    } 
                    else if (xamlPropertyNode.PropName == XamlTemplateSerializer.SetterTargetAttributeName)
                    { 
                        ThrowException(SRID.TargetNameNotSupportedForStyleSetters, 
                                       xamlPropertyNode.LineNumber,
                                       xamlPropertyNode.LinePosition); 
                    }
                }
                else if (_inSetterDepth < 0 && !_inEventSetter)
                { 
                    // Setters & Trigger Conditions processed here.
                    if (xamlPropertyNode.PropName == XamlStyleSerializer.PropertyTriggerValuePropertyName) 
                    { 
                        _setterOrTriggerValueNode = xamlPropertyNode;
                        // Delay writing out the Value attribute until WriteEndAttributes if this is a 
                        // normal property node.  If this is a property node that was created from complex
                        // syntax, then the WriteEndAttributes has already occurred, so process the
                        // node now.
                        if (xamlPropertyNode.ComplexAsSimple) 
                        {
                            ProcessPropertyValueNode(); 
                        } 

                        return; 
                    }
                    else if (xamlPropertyNode.PropName == XamlStyleSerializer.PropertyTriggerPropertyName)
                    {
                        // Property names should be trimmed since whitespace is not significant 
                        // and can affect name resolution.
                        xamlPropertyNode.SetValue(xamlPropertyNode.Value.Trim()); 
                        _setterOrTriggerPropertyInfo = GetDependencyPropertyInfo(xamlPropertyNode); 
                    }
                    else if (xamlPropertyNode.PropName == XamlStyleSerializer.PropertyTriggerSourceName) 
                    {
                        ThrowException(SRID.SourceNameNotSupportedForStyleTriggers,
                                        xamlPropertyNode.LineNumber,
                                        xamlPropertyNode.LinePosition); 
                    }
                    else if (xamlPropertyNode.PropName == XamlTemplateSerializer.SetterTargetAttributeName) 
                    { 
                        ThrowException(SRID.TargetNameNotSupportedForStyleSetters,
                                       xamlPropertyNode.LineNumber, 
                                       xamlPropertyNode.LinePosition);
                    }
                }
 
#if PBTCOMPILER
                else if (_inEventSetter) 
                { 
                    // Check for EventSetter properties.  These aren't really stored as properties but
                    // resolved at the EventSetter end tag as events by the compiler 
                    if (xamlPropertyNode.PropName == XamlStyleSerializer.SetterEventAttributeName)
                    {
                        _event = xamlPropertyNode.Value;
                    } 
                    else if (xamlPropertyNode.PropName == XamlStyleSerializer.SetterHandlerAttributeName)
                    { 
                        _handler = xamlPropertyNode.Value; 
                    }
#if HANDLEDEVENTSTOO 
                    else if (xamlPropertyNode.PropName == XamlStyleSerializer.SetterHandledEventsTooAttributeName)
                    {
                        _handledEventsToo = Boolean.Parse(xamlPropertyNode.Value);
                    } 
#endif
                    return; 
                } 
#endif
            } 

            base.WriteProperty(xamlPropertyNode);
        }