Here is the problem. I bind TreeView to several different types of objects. Each object is a node, and SOME objects have the IsNodeExpanded property, and of course, some others are not. Here is my style:
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsNodeExpanded, Mode=TwoWay}" />
</Style>
Now the problem is to bind elements that DO NOT have this property, we get this error in the output:
System.Windows.Data Error: 39 : BindingExpression path error: 'IsNodeExpanded' property not found on 'object' ''CompensationChannel' (HashCode=56992474)'. BindingExpression:Path=IsNodeExpanded; DataItem='CompensationChannel' (HashCode=56992474); target element is 'TreeViewItem' (Name=''); target property is 'IsExpanded' (type 'Boolean')
Of course, we get many times. So I'm trying to come up with a way to switch the TreeViewItem style based on the DataType that it holds. Any idea on how to do this?
Some information: I cannot do this manually for each element, because I do not create them in XAML, they are dynamically created from the data source.
EDIT: I found this answer , but it did not work for me.
source
share