【发布时间】:2013-10-17 14:45:23
【问题描述】:
这是我的 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>
用于 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>
这是我的代码隐藏类
主代码隐藏类 MainWindow.xaml.cs 的代码
public partial class MainWindow : Window
{
public ObservableCollection<CustomComponent> SummaryViewCollection { get; set; }
public MainWindow()
{
this.SummaryViewCollection = //code to fill in the details
}
}
这是自定义组件类的代码
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;
}
}
}
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;
}
}
每次我运行它时,我都会收到以下错误“mscorlib.dll 中发生'System.StackOverflowException' 类型的未处理异常”。无法计算表达式,因为当前线程处于堆栈溢出状态。 对此有何建议?谢谢
【问题讨论】:
-
为什么要设置 ItemTemplate?我认为在您的代码中不需要这样做。
-
如果所有
//code to fill in the details都被禁用,你还会得到异常吗?当您尝试启动时,您会在某个地方反复调用自己。 -
当您在调试器中捕获异常时,是否有堆栈跟踪向我们显示它在代码中的起始位置? -
需要知道哪一行抛出了异常。在 VS 调试中,异常,CLR,抛出。然后只需在调试中运行它。如果错误不明显,请查看堆栈跟踪。
-
@gleng 你指的是哪个项目模板?