0

I'm trying to bind to a CollectionViewSource nested property (CVS.View.Groups.Count) and it doesn't seem to work in code :

Binding binding = new Binding();
binding.Path = new PropertyPath("View.Groups.Count");
binding.Mode = BindingMode.OneWay;
binding.Source = CVS;
BindingOperations.SetBinding(this, ValueProperty, binding);

But it's working well in WPF/xaml.

<DataTrigger Binding="{Binding Path=CVS.View.Groups.Count, Mode=OneWay}" Value="1">

So I'm wondering what is the difference between these both approach and what is wrong in code way binding. Meanwhile this kind of code is working well on no-nested property when it's a simple dependency property in a dependency object, so I suppose there is a problem with provided PropertyPath..

Any help would be appreciated.

tuxy42
  • 368
  • 3
  • 6

1 Answers1

0

I succeeded in resolve the problem by changing the binding source. Instead of passing the dependency object directly I create a Windows.Forms.BindingSource with the dependency object and I set this object as source of binding. In this way the binding is now working well.

Binding binding = new Binding();
binding.Path = new PropertyPath("View.Groups.Count");
binding.Mode = BindingMode.OneWay;

System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource(DevicesInAlarmCVS, null);
binding.Source = bs;

BindingOperations.SetBinding(this, ValueProperty, binding);

It seems to be linked to a change in .NET framework 4.0 : Does data binding support nested properties in Windows Forms?

Hope that's can help

Community
  • 1
  • 1
tuxy42
  • 368
  • 3
  • 6