Hi,
I am working with the 'XamDataTree 2010 vol 3', as infragistics previous version lacks a TreeView control I am trying to migrate from my previous standard TreeView to Infragistics XamDataTree (main reason is theming and styling), for my surprise infragistics treeview follows a diferent path than the standard one. Not similar to the Silverlight XamTree which follows a much more common approach compared to the standard treeview.
However, everything resumes to find out how to put all the functionalities together again. My code so far can bind to a collection, display hierarchical information and bind to an 'IsExpanded' property on my view model.
<ig:XamDataTree ItemsSource="{Binding Catalogs}" Grid.Row="1">
<ig:XamDataTree.GlobalNodeLayouts>
<ig:NodeLayout Key="itemLayout" TargetTypeName="TreeViewItemViewModel" IsExpandedMemberPath="IsExpanded">
<ig:NodeLayout.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="{Binding Data.ImagePath}" />
<TextBlock Text="{Binding Data.Name}" />
</StackPanel>
</DataTemplate>
</ig:NodeLayout.ItemTemplate>
</ig:NodeLayout>
</ig:XamDataTree.GlobalNodeLayouts>
</ig:XamDataTree>
Right now, I am looking forward to bind the XamDataTreeNode item to an IsSelected property on my view model, but I cannot figure out how to target the XamDataTreeNode item.
Any help would be appreciated,
Regards,
Pablo
PS: Sorry about the code snippet formatting.
Hello!
If you submit a sample project that illustrates the XAML and code you are working with, I will refactor the project to demonstrate how you can utilize MVVM with it and re-submit the project back here. Please remove binaries and the XAP file before compressing it and adding it as an attachment to the forums as there is a size limit for attachments.
Sincerely,
We would like to see a simple sample of XamDataTree using ViewModel to get the ActiveNode, that's all.. anybody with a solution on this fail ???
Hello,
Until this feature request is met, you can easily implement your own bindable property. Wrap the XamDataTree in a UserControl or derive a new class from XamDataTree. In the code for either implement a DependencyProperty that represents the ActiveNode or the SelectedItem when there is only one selected. Then if using a UserControl add an Event handler or if in a derived class override either the ActiveNodeChanged event of the SelectedNodesCollectionChanged event. In these event handlers you would set your DependencyProperty that represents the ActiveNode or the SelectedNode. Now any property in your View Model bound to that new property will be notified when the AcitveNode or when a node is selected.
Let me know if you need further help with this.
Hey guys,
I too have been attempting to use the XamDataTree in place of the stock WPF TreeView and am a little disappointed in its current feature set and MVVM implementation. I also ran into the need to have a XamDataTreeNode.IsSelected property bound to a property on it's data object. Since this wasn't available inherently I put together what can best be described as a hack.
I handled the InitializeNode event on the XamDataTree and in the event set a reference of the created XamDataTreeNode to its bound data object. This way I can update the XamDataTreeNode.IsSeleted property whenever the data object's property is updated. Attached is a sample application that demonstrates this.
As you type a path into the TextBox at the top the corresponding node at the end of the path is selected and parent nodes are expanded on the way.
This seems to work as desired, however I've come across an issue that hopefully someone can give me a suggested solution to. Since my approach to setting the XamDataTreeNode.IsSelected property requires the XamDataTreeNode to be initialized before I can set it from my data object, it does not work when the target node is outside the current viewable area of the tree. For example in my image above, if you were to resize the window so that Node 2-3 was out of view to the bottom it would not become selected if you pasted the shown path into the TextBox. However as soon as you scroll the XamDataTree down to where that node would come into view it becomes selected since the XamaDataTreeNode for it is then initialzied.
To reproduce this launch my sample application and before doing anything else resize the window.
Then paste this text into the TextBox at the top: Node 5-1\Node 4-2\Node 3-3\Node 2-3
You'll notice that nothing appears to visually change, and if you have a breakpoint around line 149 in TestClass.cs where it reads this.IsSelected = true, and then step into the property setter you'll notice that the object's reference to a XamDataTreeNode is null, therefore it doesn't get set and the node is not selected.
Any suggestions, comments, or contributions would be greatly appreciated!
Thanks for the sample, I was able to easily understand your issue.
I was able to achieve your scenario with single line of code, it uses the XamDataTreeNode API though:
Try adding the following line to your TestClass.SelectNode() method, before calling recursively node.SelectNode(nodePathList) (around line 144):
this.XamNode.Nodes.Single(n => n.Data == node).IsActive = true;
It is not that clean, but it does the job.
HTH,
Thank you Stoimen!
I appreciate the quick response. That was just the piece of duct tape I needed to get it all working!
Hopefully this post can help others out there accomplish a similar thing until you build something into your control to handle it cleanly.
Thank you again.