예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyItem"/> class.
        /// </summary>
        public PropertyItem(PropertyDescriptor property, object instance)
        {
            Property = property;
            Instance = instance;

            ResetCommand = new Command<object>(ResetValue, CanResetValue);
            EditBindingCommand = new Command<object>(ShowBindingEditor, o => !property.IsReadOnly);
            EditResourceCommand = new Command<object>(ShowResourceEditor, o => !property.IsReadOnly);

            _propertySortInfo = PropertySorter.GetSortInfo(property);
            _markupObject = MarkupWriter.GetMarkupObjectFor(Instance);

            property.AddValueChanged(instance, OnValueChanged);

            _dpd = DependencyPropertyDescriptor.FromProperty(property);
        }
        private string ConvertMarkupItemToString(MarkupObject item)
        {
            ValueSerializer typeSerializer = _context.GetValueSerializerFor(typeof(Type));

            Debug.Assert(typeSerializer != null, "Could not retrieve typeSerializer for Type");

            // Serialize the markup extension into a string
            StringBuilder resultBuilder = new StringBuilder();

            resultBuilder.Append('{');

            string typeName = typeSerializer.ConvertToString(item.ObjectType, _context);

            if (typeName.EndsWith("Extension", StringComparison.Ordinal))
            {
                // The "Extension" suffix is optional, much like the Attribute suffix of an Attribute.
                // The normalized version is without the suffix.
                resultBuilder.Append(typeName, 0, typeName.Length - EXTENSIONLENGTH);
            }
            else
            {
                resultBuilder.Append(typeName);
            }

            bool first           = true;
            bool propertyWritten = false;

            foreach (MarkupProperty property in item.Properties)
            {
                resultBuilder.Append(first ? " " : ", ");

                first = false;
                if (!property.IsConstructorArgument)
                {
                    resultBuilder.Append(property.Name);
                    resultBuilder.Append('=');
                    propertyWritten = true;
                }
                else
                {
                    Debug.Assert(!propertyWritten, "An argument was returned after a property was set. All arguments must be returned first and in order");
                }

                string value = property.StringValue;

                if (value != null && value.Length > 0)
                {
                    if (value[0] == '{')
                    {
                        if (value.Length > 1 && value[1] == '}')
                        {
                            // It is a literal quote, remove the literals and write the text with escapes.
                            value = value.Substring(2);
                        }
                        else
                        {
                            // It is a nested markup-extension, just insert the text literally.
                            resultBuilder.Append(value);
                            continue;
                        }
                    }

                    // Escape the string
                    for (int i = 0; i < value.Length; i++)
                    {
                        char ch = value[i];
                        switch (ch)
                        {
                        case '{':
                            resultBuilder.Append(@"\{");
                            break;

                        case '}':
                            resultBuilder.Append(@"\}");
                            break;

                        case ',':
                            resultBuilder.Append(@"\,");
                            break;

                        default:
                            resultBuilder.Append(ch);
                            break;
                        }
                    }
                }
            }
            resultBuilder.Append('}');

            return(resultBuilder.ToString());
        }
 public MarkupObjectWrapper(MarkupObject baseObject)
 {
     _baseObject = baseObject;
 }
 public ExtensionSimplifierMarkupObject(MarkupObject baseObject, IValueSerializerContext context)
     : base(baseObject)
 {
     _context = context;
 }
    internal void UpdateAdvanceOptionsForItem( MarkupObject markupObject, DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, 
                                                out string imageName, out object tooltip )
    {
      imageName = "AdvancedProperties11";
      tooltip = "Advanced Properties";

      bool isResource = false;
      bool isDynamicResource = false;

      var markupProperty = markupObject.Properties.Where( p => p.Name == PropertyName ).FirstOrDefault();
      if( markupProperty != null )
      {
        //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style
        isResource = ( markupProperty.Value is Style );
        isDynamicResource = ( markupProperty.Value is DynamicResourceExtension );
      }

      if( isResource || isDynamicResource )
      {
        imageName = "Resource11";
        tooltip = "Resource";
      }
      else
      {
        if( ( dependencyObject != null ) && ( dpDescriptor != null ) )
        {
          if( BindingOperations.GetBindingExpressionBase( dependencyObject, dpDescriptor.DependencyProperty ) != null )
          {
            imageName = "Database11";
            tooltip = "Databinding";
          }
          else
          {
            BaseValueSource bvs =
              DependencyPropertyHelper
              .GetValueSource( dependencyObject, dpDescriptor.DependencyProperty )
              .BaseValueSource;

            switch( bvs )
            {
              case BaseValueSource.Inherited:
              case BaseValueSource.DefaultStyle:
              case BaseValueSource.ImplicitStyleReference:
                imageName = "Inheritance11";
                tooltip = "Inheritance";
                break;
              case BaseValueSource.DefaultStyleTrigger:
                break;
              case BaseValueSource.Style:
                imageName = "Style11";
                tooltip = "Style Setter";
                break;

              case BaseValueSource.Local:
                imageName = "Local11";
                tooltip = "Local";
                break;
            }
          }
        }
      }
    }
    internal void UpdateAdvanceOptionsForItem( MarkupObject markupObject, DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, 
                                                out object tooltip )
    {
      tooltip = StringConstants.AdvancedProperties;

      bool isResource = false;
      bool isDynamicResource = false;

      var markupProperty = markupObject.Properties.Where( p => p.Name == PropertyName ).FirstOrDefault();
      if( ( markupProperty != null ) 
        && ( markupProperty.PropertyType != typeof( object ) ) 
        && !markupProperty.PropertyType.IsEnum 
        && !markupProperty.PropertyType.IsArray )
      { 
        //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style
        isResource = ( markupProperty.Value is Style );
        isDynamicResource = ( markupProperty.Value is DynamicResourceExtension );
      }

      if( isResource || isDynamicResource )
      {
        tooltip = StringConstants.Resource;
      }
      else
      {
        if( ( dependencyObject != null ) && ( dpDescriptor != null ) )
        {
          if( BindingOperations.GetBindingExpressionBase( dependencyObject, dpDescriptor.DependencyProperty ) != null )
          {
            tooltip = StringConstants.Databinding;
          }
          else
          {
            BaseValueSource bvs =
              DependencyPropertyHelper
              .GetValueSource( dependencyObject, dpDescriptor.DependencyProperty )
              .BaseValueSource;

            switch( bvs )
            {
              case BaseValueSource.Inherited:
              case BaseValueSource.DefaultStyle:
              case BaseValueSource.ImplicitStyleReference:
                tooltip = StringConstants.Inheritance;
                break;
              case BaseValueSource.DefaultStyleTrigger:
                break;
              case BaseValueSource.Style:
                tooltip = StringConstants.StyleSetter;
                break;

              case BaseValueSource.Local:
                tooltip = StringConstants.Local;
                break;
            }
          }
        }
      }
    }
        private string ConvertMarkupItemToString(MarkupObject item)
        {
            ValueSerializer typeSerializer = _context.GetValueSerializerFor(typeof(Type));
            Debug.Assert(typeSerializer != null, "Could not retrieve typeSerializer for Type");

            // Serialize the markup extension into a string
            StringBuilder resultBuilder = new StringBuilder();
            resultBuilder.Append('{');
            
            string typeName = typeSerializer.ConvertToString(item.ObjectType, _context);
            
            if (typeName.EndsWith("Extension", StringComparison.Ordinal))
            {
                // The "Extension" suffix is optional, much like the Attribute suffix of an Attribute.
                // The normalized version is without the suffix.
                resultBuilder.Append(typeName, 0, typeName.Length - EXTENSIONLENGTH);
            }
            else
            {
                resultBuilder.Append(typeName);
            }
            
            bool first = true;
            bool propertyWritten = false;
            
            foreach (MarkupProperty property in item.Properties)
            {
                resultBuilder.Append(first ? " " : ", ");

                first = false;
                if (!property.IsConstructorArgument)
                {
                    resultBuilder.Append(property.Name);
                    resultBuilder.Append('=');
                    propertyWritten = true;
                }
                else
                {
                    Debug.Assert(!propertyWritten, "An argument was returned after a property was set. All arguments must be returned first and in order");
                }
                
                string value = property.StringValue;
                
                if (value != null && value.Length > 0)
                {
                    if (value[0] == '{')
                    {
                        if (value.Length > 1 && value[1] == '}')
                        {
                            // It is a literal quote, remove the literals and write the text with escapes.
                            value = value.Substring(2);
                        }
                        else
                        {
                            // It is a nested markup-extension, just insert the text literally.
                            resultBuilder.Append(value);
                            continue;
                        }
                    }

                    // Escape the string
                    for (int i = 0; i < value.Length; i++)
                    {
                        char ch = value[i];
                        switch (ch)
                        {
                            case '{':
                                resultBuilder.Append(@"\{");
                                break;
                            case '}':
                                resultBuilder.Append(@"\}");
                                break;
                            case ',':
                                resultBuilder.Append(@"\,");
                                break;
                            default:
                                resultBuilder.Append(ch);
                                break;
                        }
                    }
                }
            }
            resultBuilder.Append('}');

            return resultBuilder.ToString();
        }
 public MarkupObjectWrapper(MarkupObject baseObject)
 {
     _baseObject = baseObject;
 }
 public ExtensionSimplifierMarkupObject(MarkupObject baseObject, IValueSerializerContext context)
     : base(baseObject) 
 {
     _context = context;
 }
        // Token: 0x0600247B RID: 9339 RVA: 0x000B0C84 File Offset: 0x000AEE84
        private string ConvertMarkupItemToString(MarkupObject item)
        {
            ValueSerializer valueSerializerFor = this._context.GetValueSerializerFor(typeof(Type));
            StringBuilder   stringBuilder      = new StringBuilder();

            stringBuilder.Append('{');
            string text = valueSerializerFor.ConvertToString(item.ObjectType, this._context);

            if (text.EndsWith("Extension", StringComparison.Ordinal))
            {
                stringBuilder.Append(text, 0, text.Length - 9);
            }
            else
            {
                stringBuilder.Append(text);
            }
            bool flag = true;

            foreach (MarkupProperty markupProperty in item.Properties)
            {
                stringBuilder.Append(flag ? " " : ", ");
                flag = false;
                if (!markupProperty.IsConstructorArgument)
                {
                    stringBuilder.Append(markupProperty.Name);
                    stringBuilder.Append('=');
                }
                string text2 = markupProperty.StringValue;
                if (text2 != null && text2.Length > 0)
                {
                    if (text2[0] == '{')
                    {
                        if (text2.Length <= 1 || text2[1] != '}')
                        {
                            stringBuilder.Append(text2);
                            continue;
                        }
                        text2 = text2.Substring(2);
                    }
                    foreach (char c in text2)
                    {
                        if (c != ',')
                        {
                            if (c != '{')
                            {
                                if (c != '}')
                                {
                                    stringBuilder.Append(c);
                                }
                                else
                                {
                                    stringBuilder.Append("\\}");
                                }
                            }
                            else
                            {
                                stringBuilder.Append("\\{");
                            }
                        }
                        else
                        {
                            stringBuilder.Append("\\,");
                        }
                    }
                }
            }
            stringBuilder.Append('}');
            return(stringBuilder.ToString());
        }