Hi, I am experiencing some binding issues with XamDataTree v13.1 for WPF.
I have some triggers in my global node layouts that work perfectly, but regardless of that bindingexpressen errors occur in the output.
The code below is fetched from a view with a viewmodel called SituationTreeViewModel. This viewmodel contains a datasource for the tree called SituationWrappers:
<ig:XamDataTree Name="Tree" Grid.Row="1" VerticalAlignment="Top" ItemsSource="{Binding SituationWrappers}">
<ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="SituationViewLayout" TargetTypeName="SituationWrapper" DisplayMemberPath="Name" ExpandedIconTemplate="{StaticResource SituationIconTemplate}" CollapsedIconTemplate="{StaticResource SituationIconTemplate}"> <ig:NodeLayout.NodeStyle> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Data.IsActive}" Value="False"> <Setter Property="FrameworkElement.Opacity" Value="0.5"/> </DataTrigger> <DataTrigger Binding="{Binding Data.IsVisible}" Value="True"> <Setter Property="TextBlock.FontWeight" Value="Bold"/> </DataTrigger> </Style.Triggers> </Style> </ig:NodeLayout.NodeStyle> </ig:NodeLayout> </ig:XamDataTree.GlobalNodeLayouts></ig:XamDataTree>
As I mentioned the triggers given in the global node layouts work, but for some reason the tree tries to first access the given data-properties on the root view model itself (SituationTreeViewModel). This results in the following errors:
System.Windows.Data Error: 40 : BindingExpression path error: 'Data' property not found on 'object' ''SituationTreeViewModel' (HashCode=12529951)'. BindingExpression:Path=Data.IsActive; DataItem='SituationTreeViewModel' (HashCode=12529951); target element is 'XamDataTreeNodeControl' (Name=''); target property is 'NoTarget' (type 'Object')System.Windows.Data Error: 40 : BindingExpression path error: 'Data' property not found on 'object' ''SituationTreeViewModel' (HashCode=12529951)'. BindingExpression:Path=Data.IsVisible; DataItem='SituationTreeViewModel' (HashCode=12529951); target element is 'XamDataTreeNodeControl' (Name=''); target property is 'NoTarget' (type 'Object')
Is there a way to avoid these binding issues, I'd rather not have them cluttering up my output log?
Hope you can help,
Best Regards,
Tommy W.
Hi,
The problem occurs when you treeview items are actually viewmodels themselves. So you have a mainview and mainviewmodel, the mainview has the tree on it and the list of items that binds to the tree are on the mainviewmodel. The list of items themselves are actually a list of viewmodels. It binds fine but the xamdatatree always looks at mainviewmodel not the actual tree viewmodel.
This you notice when you try and do the following
<ig:XamDataTree.ContextMenu>
<ContextMenu x:Name="WorkQueueItemMenu">
<MenuItem Header="View"
Command="{Binding OpenCommand}"
CommandParameter="{Binding}"/>
it passes back the mainviewmodel item and not the selected node as the binding.
kind regards,
Anne
Sorry will try mock up app when I get a chance
Hello Anne,
Thank you for your post. I have been looking into it, but since I am not aware of your data structure I cannot say what causes your issue, so could you please send an isolated sample project, where this is reproduced, so I can investigate it further for you.
Looking forward for your reply.
Hi
I have the same problem as was reported here, I was wondering if it had been resolved. Seems like the tree always looks at root viewmodel first. Any way to fix this, Tried suggestion but then it does not work at all.
Hello Tommy,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
Thank you for your post. I have been looking into it and I can suggest you change your Bindings to IsActive and IsVisible only, but since I am not aware of your data structure I cannot assure you that this is will work for you. If it doesn’t, could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.