Initially I had this code in XAML:
<CollectionViewSource x:Name="cSource">
<CollectionViewSource.Source>
<Binding Source="{StaticResource NameOfXmlDataProvider}" XPath="letter"/>
</CollectionViewSource.Source>
<CollectionViewSource>
But I wanted to keep a binding object in the C# code, to be able to dynamically alter it's xpath. Currently I have this code:
CollectionViewSource viewSource = this.FindResource("cSource") as CollectionViewSource;
Binding binding = new Binding( "Source" );
binding.Source = _xmlDataProvider;
binding.XPath = "/new/path/to/nodes";
BindingOperations.SetBinding( viewSource, CollectionViewSource.SourceProperty, binding );
This compiles and doesn't complain but when called it only leads to an empty list. I can't seem to find related examples in the web - most of them deal with the data providers but I want to change the binding.
- Anybody knows how to fix this?
- Or is there a better way to do this?
- Maybe from retrieving the binding object from the collectionview and changing it?