WPF telerik TreeView控件中的mscorlib.dll中发生了未处理的"System.StackOverflowException"类型异常

Sik*_*e12 0 .net c# wpf xaml telerik

这是我的xaml

<Window.Resources>
    <sampleData:MainWindow  x:Key="DataSource"/>
    <DataTemplate x:Key="CustomComponentParameter">
        <TextBlock Text="{Binding Name}" />
    </DataTemplate>
    <HierarchicalDataTemplate x:Key="CustomComponent" ItemTemplate="{StaticResource CustomComponentParameter}"
       ItemsSource="{Binding Parameters }">
        <TextBlock Text="{Binding Name}" />
    </HierarchicalDataTemplate>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

用于telerik控制

    <telerik:RadTreeView ItemsSource="{Binding Source={StaticResource DataSource},Path=SummaryViewCollection}"  ItemTemplate="{StaticResource CustomComponent}" HorizontalAlignment="Left" Height="77" Margin="345,482,0,0" VerticalAlignment="Top" Width="449">

    </telerik:RadTreeView>
Run Code Online (Sandbox Code Playgroud)

这是我的Codebehind课程

主要Codebehind类MainWindow.xaml.cs的代码

 public partial class MainWindow : Window
 {
    public ObservableCollection<CustomComponent> SummaryViewCollection { get; set; }
    public MainWindow()
    {          
       this.SummaryViewCollection = //code to fill in the details 
    }           
 }
Run Code Online (Sandbox Code Playgroud)

这是CustomComponentClass的代码

public class CustomComponent
{

    private ObservableCollection<CustomComponentParameter> parameters = new ObservableCollection<CustomComponentParameter>();


    public string Name
    {
        get;
        set;        
    }     

    public ObservableCollection<CustomComponentParameter> Parameters
    {
        get
        {
            return this.parameters;
        }

        set
        {
            this.parameters = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

CustomComponentParameter类的代码

public class CustomComponentParameter
{       
    public string Name
    {
        get;set;
    }

    public string Value
    {
        get;set;
    }

    public bool HasErrors
    {
        get;set;
    }

    public bool IsDuplicate
    {
        get;set;
    }


    public bool IsMissing
    {
        get; set;
    }
}
Run Code Online (Sandbox Code Playgroud)

每次我运行它我得到以下错误"mscorlib.dll中发生了'System.StackOverflowException'类型的未处理异常".无法计算表达式,因为当前线程处于堆栈溢出状态.有什么建议吗?谢谢

Nit*_*tin 5

该计算器的例外是发生,因为你正在创建的实例MainWindowMainWindow's Resources<sampleData:MainWindow x:Key="DataSource"/>它发送程序转换成无限递归

如果你想设置DataContext窗口的自我,然后删除此行并在你的构造MainWindow

public MainWindow()
{          
   InitializeComponents();
   this.SummaryViewCollection = //code to fill in the details 
   DataContext = this;
} 
Run Code Online (Sandbox Code Playgroud)

然后你的绑定将是公正的

 <telerik:RadTreeView ItemsSource="{Binding Path=SummaryViewCollection}"  ItemTemplate="{StaticResource CustomComponent}" HorizontalAlignment="Left" Height="77" Margin="345,482,0,0" VerticalAlignment="Top" Width="449">

</telerik:RadTreeView>
Run Code Online (Sandbox Code Playgroud)