Comportamientos de fusión: valores de colección predeterminados no visibles en Blend

I've crated a Behavior that works well with non-collection properties but the Blend designer does not "see" default values with collections. Ex:

//WORKS!! (Enabled defaults to "true" (good))
private bool enabled = true;
[Category("Physics"), Description("")]
public bool Enabled
{
     get { return enabled; }
     set
     {
           enabled = value;
     }
}

//DOESN'T WORK! The collection is always blank unless I manually add the items to the collection
private List<Category> collisionCategories = new List<Category>() { Category.All };
[Category("Physics"), Description("")]
public List<Category> CollisionCategories
{
    get { return collisionCategories; }
    set
    {
        collisionCategories = value;
    }
}

Why is "Category.All" not already in my list?

preguntado el 08 de enero de 11 a las 16:01

2 Respuestas

In Blend there is a little square to the right of your collection property. If it is all dark then your collection has its "default" value, which is the value you set. If you want to override the default value of a collection property, you have to specify the items you would like to add to the blank collection. Then the little square will show a white outline.

This is just the way that all collection properties work in Blend, and the Visual Studio designer for that fact. But rest assured that if the user doesn't specify a value for your collection that the default value will apply.

Respondido el 09 de enero de 11 a las 06:01

Does it work like this:

private List<Category> collisionCategories =
       new List<Category>(new Category[] { Category.All });

Respondido el 08 de enero de 11 a las 20:01

using the compact framework so non-generic collections are not an option. - vidalsasoon

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.