Hi,
I have a RadTreeView where data is populated from an xml using XmlDataProvider. I would like to bind the SelectedItem of TreeView to a ViewModel property of type string. When I do the binding using SelectedItem={Binding mydata}", the value mydata is set to System.Xml.XmlElement type.
I was able to find the logic to get the exact value. For testing purpose, I created a new TextBox control to retreive the exact selected data.
<TextBox DataContext="{Binding ElementName=ReportersTreeView, Path=SelectedItem}" Grid.Row="6" Text="{Binding XPath=@Name}"></TextBox>
However in real scenario, I don't need this TextBox.
I want to know how can I integrate this code to my tree view control such that XPath=@Name is correctly retrieved from SelectedItem and set to my viewmodel property?
Below is my TreeView control and my Template.
<HierarchicalDataTemplate x:Key="NodeTemplate">
<TextBlock x:Name="tb"/>
<HierarchicalDataTemplate.ItemsSource>
<Binding XPath="child::node()" />
</HierarchicalDataTemplate.ItemsSource>
<HierarchicalDataTemplate.Triggers>
<!--<DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
<Setter TargetName="tb" Property="Text" Value="{Binding XPath = @name}"></Setter>
</DataTrigger>-->
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tb" Property="Text" Value="{Binding Path=Attributes[Name].Value}"></Setter>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
<XmlDataProvider x:Key="ReportersDataProvider" Source="ProbesTree.xml"
XPath="*">
<telerik:RadTreeView Grid.Row="2" IsDragDropEnabled="True" Name="ReportersTreeView" SelectionMode="Single" IsSingleExpandPath="False" IsLineEnabled="True" AutomationProperties.AutomationId ="ReportersTreeView" VerticalAlignment="Stretch"
ItemTemplate= "{StaticResource NodeTemplate}" ItemsSource="{Binding Source={StaticResource ReportersDataProvider}}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
Please help.!!!!
Thanks,
Divya
I have a RadTreeView where data is populated from an xml using XmlDataProvider. I would like to bind the SelectedItem of TreeView to a ViewModel property of type string. When I do the binding using SelectedItem={Binding mydata}", the value mydata is set to System.Xml.XmlElement type.
I was able to find the logic to get the exact value. For testing purpose, I created a new TextBox control to retreive the exact selected data.
<TextBox DataContext="{Binding ElementName=ReportersTreeView, Path=SelectedItem}" Grid.Row="6" Text="{Binding XPath=@Name}"></TextBox>
However in real scenario, I don't need this TextBox.
I want to know how can I integrate this code to my tree view control such that XPath=@Name is correctly retrieved from SelectedItem and set to my viewmodel property?
Below is my TreeView control and my Template.
<HierarchicalDataTemplate x:Key="NodeTemplate">
<TextBlock x:Name="tb"/>
<HierarchicalDataTemplate.ItemsSource>
<Binding XPath="child::node()" />
</HierarchicalDataTemplate.ItemsSource>
<HierarchicalDataTemplate.Triggers>
<!--<DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
<Setter TargetName="tb" Property="Text" Value="{Binding XPath = @name}"></Setter>
</DataTrigger>-->
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="tb" Property="Text" Value="{Binding Path=Attributes[Name].Value}"></Setter>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
<XmlDataProvider x:Key="ReportersDataProvider" Source="ProbesTree.xml"
XPath="*">
<telerik:RadTreeView Grid.Row="2" IsDragDropEnabled="True" Name="ReportersTreeView" SelectionMode="Single" IsSingleExpandPath="False" IsLineEnabled="True" AutomationProperties.AutomationId ="ReportersTreeView" VerticalAlignment="Stretch"
ItemTemplate= "{StaticResource NodeTemplate}" ItemsSource="{Binding Source={StaticResource ReportersDataProvider}}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
Please help.!!!!
Thanks,
Divya