Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
XamDataTree - Item template not displaying correctly
posted

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.

Parents
No Data
Reply
  • 34830
    Verified Answer
    Offline posted

    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.

Children