我正在尝试绑定到 CollectionViewSource 嵌套属性(CVS.View.Groups.Count),但它似乎在代码中不起作用:
Binding binding = new Binding();
binding.Path = new PropertyPath("View.Groups.Count");
binding.Mode = BindingMode.OneWay;
binding.Source = CVS;
BindingOperations.SetBinding(this, ValueProperty, binding);
但它在 WPF/xaml 中运行良好。
<DataTrigger Binding="{Binding Path=CVS.View.Groups.Count, Mode=OneWay}" Value="1">
所以我想知道这两种方法之间有什么区别以及代码方式绑定有什么问题。同时,当它是依赖对象中的简单依赖属性时,这种代码在非嵌套属性上运行良好,所以我认为提供的 PropertyPath 存在问题。
任何帮助,将不胜感激。