今天帮忙同事调试一个自定义Panel的问题, 很奇怪, 利用Binding可以通过ItemSource来添加控件,但是在Listbox的xaml里添加几个ListboxItem却报异常: VisualTree of ItemsPanelTemplate must be a single element. 原因有2: 1)ListBox的ItemPanelTemplate使用自定义Panel时, 需要设置IsItemHost="True" 2)这个自定义Panel里自己实现了很多依赖属性…
依赖属性 ".NET properties are nothing more than syntactic sugar over set and get methods." 我们知道.NET的属性只不过是get/set方法的语法糖衣. "Dependency properties are the workhorse of WPF. This infrastructure provides for many of WPF's features, such as data bin…