WPF - UserControl default Content attribute

前端 未结 2 1999
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 14:22

I\'m creating a UserControl and I just can\'t remember the name of the attribute which you use to decorate the property which you want to act as the default content property. <

相关标签:
2条回答
  • 2021-02-02 14:41

    ContentPropertyAttribute

    0 讨论(0)
  • 2021-02-02 15:01

    I also found the code for supporting collections as the content property on MSDN. TOM_C is to thank for this.

    [ContentProperty("SomeObjects")]
    public class SomeContainer
    {
        private List<SomeObject> _someObjects;
        public List<SomeObject> SomeObjects
        {
            get
            {
                if (null == _someObjects)
                    _someObjects = new List<SomeObject>();
                return _someObjects;
            }
        }
    }
    

    XAML:

    <SomeContainer>
        <SomeObject/>
        <SomeObject/>
        <SomeObject/>
    </SomeContainer>
    
    0 讨论(0)
提交回复
热议问题