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.
Hi. I created a class that inherits XamDataTree with a dependency property for the SelectedNode. I overrode the OnActiveNodeChanged event and set the new property. However my view model is not seeing the change. I am wondering if I am missing something. Any help would be appreciated.
Here is the XamTree class
Public Class XamDataTreeExtended Inherits XamDataTree Public Shared ReadOnly SelectedNodeProperty As DependencyProperty = DependencyProperty.Register("SelectedNode", GetType(XamDataTreeNode), GetType(XamDataTreeExtended), New PropertyMetadata(AddressOf SelectedNodeChanged)) Public Property SelectedNode() As XamDataTreeNode Get Return CType(GetValue(SelectedNodeProperty), XamDataTreeNode) End Get Set(ByVal value As XamDataTreeNode) SetValue(SelectedNodeProperty, value) End Set End Property Private Shared Sub SelectedNodeChanged(ByVal s As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs) 'do nothing Dim tree = DirectCast(s, XamDataTreeExtended) tree.OnPropertyChanged("SelectedNode") End Sub Protected Overrides Sub OnActiveNodeChanged(args As Infragistics.Controls.Menus.ActiveNodeChangedEventArgs) SelectedNode = Me.ActiveNode MyBase.OnActiveNodeChanged(args) End Sub End Class
Here is some of the Xaml for the tree:
<infra:XamDataTreeExtended x:Name="xamTree" AllowDrop="True" IsDropTarget="True" Grid.Row="0" ItemsSource="{Binding RootFolderContactsNode.SubItemsSorted}" MaxHeight="550" NodeDragDrop="xamTree_NodeDragDrop" Background="Transparent" NodeLineVisibility="Visible" SelectedNode="{Binding SelectedNode, Mode=TwoWay}">
...
</infra:XamDataTreeExtended>
In my view model:
Private _selectedNode As FolderContactTreeNode Public Property SelectedNode As FolderContactTreeNode Get Return _selectedNode End Get Set(value As FolderContactTreeNode) _selectedNode = value '<----Not being Hit OnPropertyChanged("SelectedNode") End Set End Property
Forget it. I figured it out :
My View Model was wrong. The property should have been of Type XamDataTreeNode instead of the class for the Data of the Node
I just want to let wmlanza know that this solution worked out perfectly for my needs. Thanks for sharing!