How to bind an ItemsSource to a private property

前端 未结 4 1194
情书的邮戳
情书的邮戳 2021-01-11 19:25

How to bind WPF an ItemsSource to a private property?



        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-11 20:03

    If you really really wanted to do this, you would have to provide a custom type descriptor, by implementing ICustomTypeDescriptor - that provides the extra property via a custom PropertyDescriptor alongisde the regular public properties. You can implement this interface on the type itself, or via TypeDescriptionProvider; the latter is preferred, as it works in more scenarios (things like empty lists, without needing to also provide a custom list with an ITypedList implementation). This is a lot of work, and it really isn't worth it except in extreme cases. But it can be done.

提交回复
热议问题