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
80
Binding elements to the XamDataTree
posted

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

{

get

{

return _name;

}

set

{

_name = value;

OnPropertyChanged("Name");

}

}

public List<string> NamespaceUris

{

get

{

return _namespaceUris;

}

set

{

_namespaceUris = value;

OnPropertyChanged("NamespaceUris");

}

}

public UaStandardNode Child

{

get

{

return _child;

}

set

{

_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


Parents
No Data
Reply
  • 34430
    Verified Answer
    Offline posted

    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,
    Andrew
    Associate Developer

    XamDataTreeDemo.zip
Children