简体   繁体   English

混合行为-默认集合值在混合中不可见

[英]Blend behaviors - Default collection values not visible in Blend

I've crated a Behavior that works well with non-collection properties but the Blend designer does not "see" default values with collections. 我已经创建了一个可以很好地与非集合属性配合使用的行为,但是Blend设计器无法“看到”集合的默认值。 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? 为什么“ Category.All”尚未出现在我的列表中?

Does it work like this: 它是这样工作的吗:

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

In Blend there is a little square to the right of your collection property. 在Blend中,收藏属性的右侧有一个小方块。 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. 这就是所有集合属性在Blend和该事实的Visual Studio设计器中工作的方式。 But rest assured that if the user doesn't specify a value for your collection that the default value will apply. 但是请放心,如果用户未为您的集合指定值,则将应用默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM