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.
Thanks a lot for posting your solution. I will follow that path if I finally go with Infragistics: but think is not happenning... suddenly, now managers panic when they find code behind.
Well, I wouldn't go as far as to dismiss code behind altogether. Having said that, I must agree that this specific control seems to be lacking in the MVVM compartment.
I'm facing the exactly same issue. My viewmodel needs to know, wich node is selected. Did someone figured out a "clean" VMMV solution?
Supposing you need a one-time "binding" (e.g. on XamDataTree.Loaded), you could call
SelectNodes(dataTree.Nodes);
where SelectNodes() is as follows:
private void SelectNodes(IEnumerable<XamDataTreeNode> nodes) { foreach (var node in nodes) { if (((ViewModelBase)node.Data).IsSelected) dataTree.SelectionSettings.SelectedNodes.Add(node); SelectNodes(node.Nodes); } }
Please note that you'll also need to take care of expansion state (i.e. add the IsExpanded property to ViewModelBase, set IsExpandedMemberPath to IsExpanded in NodeLayout and make sure the right view models have IsExpanded set to true).
This is of course far from being a clean solution, but, well, it does the job.
I just realized that you were asking for a pure MVVM solution to binding the view model to the view. That seems utterly improbable with the current implementation.