I have the following XamDataTree:
<ig:XamDataTree ItemsSource="{Binding WaterLines}"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="Children" TargetTypeName="Line" ItemTemplate="{StaticResource LineNodeTemplate}" /> <ig:NodeLayout Key="HydrantLayout" TargetTypeName="Hydrant" ItemTemplate="{StaticResource HydrantNodeTemplate}" /> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
and here is an example of my template (hydrant template is nearly identical):
<DataTemplate x:Key="LineNodeTemplate" DataType="{x:Type ents:Line}"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> <TextBlock Text="{Binding Name}" ig:DragDropManager.DragSource="{StaticResource DragSource}"> <ig:ContextMenuService.Manager> <ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu ItemClicked="LineMenu_ItemClicked" IsVisibleChanged="XamContextMenu_IsVisibleChanged"> <ig:XamContextMenu.Items> <ig:XamMenuItem Name="LineAddHydrant" Header="Add Hydrant" /> <ig:XamMenuItem Name="LineAddLine" Header="Add Line" /> <ig:XamMenuItem Name="LineRename" Header="Rename" /> <ig:XamMenuItem Name="LineDelete" Header="Delete" /> </ig:XamContextMenu.Items> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager> </TextBlock> </StackPanel> </DataTemplate>
For some reason, regardless what I do with it, the template simply doesn't show. I can't see a single reason why that would be? I know the item has a 'Name' property and it's populated, because if I nix the template and add DisplayMemberPath="Name" to the NodeLayout, it shows perfectly.
Hello Doug,
I have been investigating into the behavior you are seeing, and the reason that your nodes are appearing blank is because your binding on your TextBlock in your DataTemplate is failing.
The DataContext of the elements inside of your DataTemplate will not be the underlying data item – it is an element called XamDataTreeNodeDataContext, which has two properties: Node and Data. The Node property returns the tree node associated with the template, and the Data property returns your underlying data item. Knowing this, you should be able to bind to Data.Name and have your tree items show up as expected.
Please let me know if you have any other questions or concerns on this matter.
That seemed to work, but now i'm coming across another issue.
All items in the XamDataTree are now using the LineNodeTemplate, regardless what their type is. It almost seems like the children of a line are using the same NodeLayout as their parent node, regardless of their type. Do you know why that would be?
Both are derived from InfrastructureBase. A Line has a List<InfrastructureBase> Children, which can consist of child lines and hydrants. It seems that NodeLayoutAssigned is reading a 'type' of InfrastractureBase, rather than hydrant or line. At this point, it might be easiest for me to create a new model for Line, used by this screen, that has two separate lists for child lines and hydrants.
Thank you for your help.
I am glad the binding issue seems to be resolved on your end.
Regarding all of your items in the XamDataTree using the LineNodeTemplate, I would be curious to know what your data structure looks like. For example, does the “Hydrant” target type derive from the “Line” type? If this is the case, then it is possible that the “Children” NodeLayout could be getting reused across your items.
A way that you can potentially catch this or get around it is by using the NodeLayoutAssigned event of the XamDataTree. Using the event arguments of this event, you can get and set the NodeLayout being assigned to a particular node.