Logo

¡Bienvenido a Stratos!

Acceder

Foros



C# PropertyGrid

Iniciado por blau, 19 de Junio de 2010, 09:35:45 PM

« anterior - próximo »

blau

Buenas, ando liado haciendo un editor para una interfaz grafica que estoy haciendo en XNA.

Estoy usando un PropertyGrid para acceder a las propiedades y modificarlas.

Pero me he encontrado con un problema, tengo una clase StyleCollection que contiene los estilos que puedo aplicar a los controles y me gustaria que se desplegara mostrnado los diversos estilos, como cuando despliegas las propiedades de una fuente, pero no consigo hacerlo.

Y luego viene el tema del Style, qur tb me gustaria que se deplegara con los colores.



Bueno, seguire indagando....

Código (csharp) [Seleccionar]

public class StyleCollection
{
       public Style Normal { get { return Styles[(int)StyleType.Normal]; } }
       public Style Over { get { return Styles[(int)StyleType.Over]; } }
       public Style Pressed { get { return Styles[(int)StyleType.Pressed]; } }
       public Style Disabled { get { return Styles[(int)StyleType.Disabled]; } }
       public Style Hidden { get { return Styles[(int)StyleType.Hidden]; } }

       public event Action StyleTransitionEnded;
       public event Action StyleTypeChanged;
}

public class Style
{
       public event Action Changed;

       public Color BorderColor { get { return _BorderColor; } set { _BorderColor = value; OnChanged(); } }
       public Color BackgroundColor { get { return _BackgroundColor; } set { _BackgroundColor = value; OnChanged(); } }
       public Color ImageColor { get { return _ImageColor; } set { _ImageColor = value; OnChanged(); } }
       public Color TextColor { get { return _TextColor; } set { _TextColor = value; OnChanged(); } }
       public Color BackgroundTextColor { get { return _BackgroundTextColor; } set { _BackgroundTextColor = value; OnChanged(); } }
       public float TransitionDuration { get { return _TransitionDuration; } set { _TransitionDuration = value; OnChanged(); } }      
}

public abstract class GuiControl
{
       public ControlCollection Controls { get; private set; }    
     
       public Skin Skin { get; set; }

       public StyleCollection Styles { get;  private set; }
       ....      
}


blau

#1
Bueno, ya lo tengo,

Código (csharp) [Seleccionar]

[TypeConverter(typeof(ExpandableObjectConverter))]
public StyleCollection Styles { get; private set; }


Pero como muestra cosas que no quiero que muestre, he creado una clase derivada de ExpandableObjectConverter que muestra solo lo que yo quiero.

Código (csharp) [Seleccionar]

public class StyleCollectionConverter : ExpandableObjectConverter
{
   public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
    {
         StyleCollection stylesCollection = value as StyleCollection;

         if (stylesCollection == null) return (null);

         List<PropertyDescriptor> propertyCollection = new List<PropertyDescriptor>();

         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);

         foreach (PropertyDescriptor prop in properties)
         {
             if (prop.PropertyType == typeof(StyleType) ||  prop.PropertyType == typeof(Style))
             {
                  propertyCollection.Add(prop);
             }
         }         
         properties = new PropertyDescriptorCollection(propertyCollection.ToArray());
         return (properties);
   }

  public override bool GetPropertiesSupported(ITypeDescriptorContext context)
  {
       return (true);
  }
}






Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.
Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.