混合行为 - 默认集合值在混合中不可见
我已经创建了一个与非集合属性配合良好的行为,但 Blend 设计器不会“看到”集合的默认值。例如:
//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;
}
}
为什么“Category.All”尚未出现在我的列表中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Blend 中,您的收藏属性右侧有一个小方块。如果全黑,那么您的集合就有其“默认”值,即您设置的值。如果要覆盖集合属性的默认值,则必须指定要添加到空白集合的项目。然后小方块就会显示出白色的轮廓。
这正是所有集合属性在 Blend 中的工作方式,也是 Visual Studio 设计器的工作方式。但请放心,如果用户没有为您的集合指定值,则将应用默认值。
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.
它是这样工作的吗:
Does it work like this: