This question is locked. New answers and comments are not allowed.
Hi,
I try to bind Xml.Linq XEelement to RadTreeView with a Converter.
I get NullReferenceException when I drop any node onto another one within the RadTreeView control.
Below is the XAML code:
| <UserControl x:Class="XmlSample.MainPage" |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| xmlns:XmlSample="clr-namespace:XmlSample" |
| xmlns:Telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
| xmlns:TelerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" > |
| <UserControl.Resources> |
| <XmlSample:XElementChildrenConverter x:Key="XElementChildrenConverter" /> |
| <Telerik:HierarchicalDataTemplate x:Key="Element" ItemsSource="{Binding ., Converter={StaticResource XElementChildrenConverter}}" > |
| <TextBlock Text="{Binding Name}" /> |
| </Telerik:HierarchicalDataTemplate> |
| </UserControl.Resources> |
| <Grid x:Name="LayoutRoot"> |
| <TelerikNavigation:RadTreeView |
| x:Name="ctrlTree" |
| IsDragDropEnabled="True" |
| ItemTemplate="{StaticResource Element}" |
| /> |
| </Grid> |
| </UserControl> |
and C# code:
| using System; |
| using System.Windows.Controls; |
| using System.Xml.Linq; |
| using System.Windows.Data; |
| namespace XmlSample |
| { |
| public partial class MainPage : UserControl |
| { |
| public MainPage() |
| { |
| InitializeComponent(); |
| XDocument xdoc = new XDocument(); |
| xdoc.Add(new XElement("root")); |
| xdoc.Root.Add(new XElement("node1")); |
| xdoc.Root.Add(new XElement("node2")); |
| xdoc.Root.Add(new XElement("node3")); |
| ctrlTree.ItemsSource = xdoc.Elements(); |
| } |
| } |
| public class XElementChildrenConverter : IValueConverter |
| { |
| public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
| { |
| if (value is XElement) |
| { |
| return (value as XElement).Elements(); |
| } |
| return null; |
| } |
| public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
| { |
| throw new NotImplementedException(); |
| } |
| } |
| } |
Are you going to fix this bug? Is there any workaround to fix the issue?
Thanks in advice.
Regards