WPF - UserControl default Content attribute

前端 未结 2 2007
隐瞒了意图╮
隐瞒了意图╮ 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 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 _someObjects;
        public List SomeObjects
        {
            get
            {
                if (null == _someObjects)
                    _someObjects = new List();
                return _someObjects;
            }
        }
    }
    

    XAML:

    
        
        
        
    
    

提交回复
热议问题