Hi,
I'm trying to bind the members(Child and NamespaceUris) of a class called Test via an observable collection Testobj as shown below. Currently I can only see something like (Collection). My aim is to show a Test node with the list of NamespaceUris and the child object(in the form of a XamDataTree, showing the Property DisplayName).
My Xaml
<ig:XamDataTree Grid.Row="1" x:Name="ulsTree" ItemsSource="{Binding Testobj}">
<ig:XamDataTree.GlobalNodeLayouts>
<ig:NodeLayout Key="Test" TargetTypeName="Test" DisplayMemberPath="NamespaceUris">
</ig:NodeLayout>
<ig:NodeLayout Key="Test1" TargetTypeName="Test" DisplayMemberPath="Child"></ig:NodeLayout> <!--The Child object is of UaStandardNode type(class UaStandardNode has a property called Children which is an observable collection of UaStandardNode) which has a property called DisplayName. Want to show it as a tree-->
</ig:XamDataTree.GlobalNodeLayouts>
</ig:XamDataTree>
The Backend code:
public ObservableCollection<Test> Testobj
{
get
if (ReferenceEquals(null, _test))
_test = new ObservableCollection<Test>();
}
return _test;
ObservableCollection<Test> _test;
public class Test : BaseViewModel
public string Name
return _name;
set
_name = value;
OnPropertyChanged("Name");
public List<string> NamespaceUris
return _namespaceUris;
_namespaceUris = value;
OnPropertyChanged("NamespaceUris");
public UaStandardNode Child
return _child;
_child = value;
OnPropertyChanged("Child");
private string _name;
private List<string> _namespaceUris = new List<string>();
private UaStandardNode _child;
I'm relatively new to WPF so I would be glad if you could correct any syntactical errors/provide any implementation suggestions.
Thanks & Regards,
Ashwin
Hello Ashwin,
The only issues that I am seeing from the code that you have provided is within the NodeLayout definitions that you are defining for your tree. Namely, the Key and DisplayMemberPath properties are incorrect.
The DisplayMemberPath of a XamDataTree's NodeLayout is meant to point at a property on the type defined by the TargetTypeName. By pointing your "Test" DisplayMemberPath at your NamespaceUris property, you are pointing it at a collection. This is why you are likely seeing a bunch of nodes that read "(Collection)". I imagine you are looking to show the Name of your Test elements, so I would recommend setting the "Test" NodeLayout's DisplayMemberPath to "Name."
Every NodeLayout after the first one will need to have its Key match the property name of the collection property that you are looking to set. I don't think I completely understand your requirement, or the structure of the tree that you're looking to show, but I am assuming on the second level, you wish to show the elements that exist inside of the NamespaceUris collection. So, you would name the Key of your second NodeLayout "NamespaceUris" and set the TargetTypeName to "String." You would not need to set a DisplayMemberPath in this case, as the type of the elements inside your NamespaceUris collection is string.
I am a little unsure of where the UaStandardNode bits come in here, so if you could please provide some more information on this, I should be able to continue assisting you on this. I have also attached a sample project that demonstrates the Test --> NamespaceUris hierarchy.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
As you rightly pointed the definition of the DisplayMemberPath and TargetTypeName was wrong. A colleague of mine gave the exact same solution and it worked. Another problem was the way I defined the child property which was an object of type UaStandardNode type. This should've replicated the Children property which is an observable collection of UaStandardNode because the collection is responsible for the tree nodes. Just to get a clearer idea I'm posting the UaStandardNode class with few properties needed for the tree.
public class UaStandardNode : DeepCloneable, IStandardNode, INodeTree<UaStandardNode>
public string DisplayName
if (AssociatedObject.UaNode == null)
return string.Empty;
if (AssociatedObject.UaNode.DisplayName !=null && AssociatedObject.UaNode.DisplayName.Length > 0 && !string.IsNullOrWhiteSpace(AssociatedObject.UaNode.DisplayName[0].Value))
return AssociatedObject.UaNode.DisplayName[0].Value;
//return name of the browse name, because the display name might be missing since is optional
return QualifiedName.Parse(AssociatedObject.UaNode.BrowseName).Name;
set{}
public ObservableCollection<UaStandardNode> Children
if (_children == null)
_children = new ObservableCollection<UaStandardNode>();
return _children;
The current working xaml:
<ig:NodeLayout Key="NameLayout" TargetTypeName="Test" DisplayMemberPath="Name">
<ig:NodeLayout Key="NamespaceUris" TargetTypeName="String">
<ig:NodeLayout Key="Objects" TargetTypeName="UaStandardNode" DisplayMemberPath="DisplayName">
I have 1 other requirement now. As you can see in the XAML above, the tree displays a parent called Test with 2 child nodes NamespaceUris and Objects as defined in the "Key" Property. Only for the second nodelayout(one with Objects as key) I don't want an additional Objects folder, rather I want to start showing the root node of the added observable collection directly.
Ashwin Fernandes