Hello.
I am using Net Advantage 2012 volume 1 and I am using the XamDataTree in an MVVM project. The tree is in a UserControl and is bound to a collection of different types of ViewModels that all derive from a common NodeViewModel class that has a Selected property. What I'm looking to do is bind the IsSelected property of the XamDataTreeNode to the Selected property of the backing ViewModel.
This works fine with the .NET TreeView. Here's the Xaml for the XamDataTree and the style targeting the XamDataTreeNode:
<Grid.Resources> <Style x:Key="XamDataTreeNodeStyle" TargetType="{x:Type ig:XamDataTreeNode}"> <Setter Property="IsSelected" Value="{Binding Selected}"/> </Style> </Grid.Resources> <ig:XamDataTree x:Name="FarmAndServerTree" Margin="5" ItemsSource="{Binding Children}" NodeLineVisibility="Visible" ActiveNodeChanged="FarmAndServerTree_ActiveNodeChanged" NodeStyle="{StaticResource XamDataTreeNodeStyle}">
Now, here's the Xaml for the .NET TreeView:
<Style x:Key="TreeViewItemStyle" TargetType="{x:Type TreeViewItem}"> <Setter Property="IsSelected" Value="{Binding Selected}" /> <Setter Property="IsExpanded" Value="True" /> <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Once" /> <EventSetter Event="TreeViewItem.MouseRightButtonDown" Handler="TreeViewItem_MouseRightButtonDown"/> </Style>
<TreeView BorderThickness="0" ItemsSource="{Binding Children }" ItemContainerStyle="{StaticResource TreeViewItemStyle}">
When I run the application with the XamDataTree and set the NodeStyle to the XamDataTreeNodeStyle, the setter of the XamDataTreeNodeStyle throws this XamlParseException at run time:
"'XamDataTreeNode' type must derive from FrameworkElement or FrameworkContentElement."
This doesn't happen with the .NET TreeView; I can bind the IsSelected property of the TreeViewItem to the Selected property of the backing ViewModels with no issues. I found this thread which looks related:
http://es.infragistics.com/community/forums/t/72638.aspx
In that thread, it was said that you can't bind to the ActiveNode of the tree because it's not a Dependency property and they offered a workaround. I would assume that this is something similar because the XamDataTreeNode isn't a FrameworkElement. Is there any way to bind the IsSelected property of the nodes to a property in the backing ViewModel?
I can get around this by handling the ActiveNodeChanged event and then extracting the ViewModel from the e.NewActiveTreeNode property. Once I have that, I can manually set the Selected property of that ViewModel, but it would be much easier if I could hook this up in Xaml like you can with the .NET TreeView.
Thanks in advance for your help.
There's nothing more that I need with this issue. Thanks.
Hello Charlie,
Thank you for your feedback. Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hello Krasimir.
No, I don't need anything else. I understand that this is a feature request and I would like to see it implemented sometime in the future; it would be a very nice enhancement.
Charlie
I am just checking if my last reply was helpful for you.
If you require any further assistance please do not hesitate to ask.
Thank you for your post. I have been looking into it and our XamDataTree does not currently supports the TreeView functionality that you have described. I can suggest using the approach that you have described, since it seems that currently, it is the best approach in this scenario. I have submitted a new Product Idea for you, for have IsSelectedMemeberPath property of the NodeLayout, which will allows choosing which property of your ViewModel will be bound to the IsSelected property of the XamDataTreeNodes. I have sent your Product Idea directly to our product management team. Our product team chooses new Product Ideas for development based on popular feedback from our customer base. Infragistics continues to monitor application development for all of our products, so as trends appear in requested ideas, we can plan accordingly.
We value your input, and our philosophy is to enhance our toolset based on customer feedback. If your idea is chosen for development, you will be notified at that time. Your reference number for this Product Idea is PI12120083
If you would like to follow up on your Product Idea at a later point, you may contact Developer Support management via email. Please include the reference number of your Product Idea in the subject and body of your email message. You can reach Developer Support management through the following email address: dsmanager@infragistics.com
Thank you for your request.