C# 如何避免非';你不总是在场吗?
我已定义以下分层数据模板:C# 如何避免非';你不总是在场吗?,c#,wpf,data-binding,C#,Wpf,Data Binding,我已定义以下分层数据模板: 子项可以是各种类型的对象。问题是,并非每种类型都实际定义了子条目。(这些是树的对象,某些条目没有子条目) 例如,这里有一个对象可以包含在具有自己的子项的子项中: public class ScriptLevelLog : LogContainer { public List<LogContainer> SubEntries { get; set; } public ScriptLevelLog() {
子项可以是各种类型的对象。问题是,并非每种类型都实际定义了子条目
。(这些是树的对象,某些条目没有子条目)
例如,这里有一个对象可以包含在具有自己的子项的子项中:
public class ScriptLevelLog : LogContainer
{
public List<LogContainer> SubEntries { get; set; }
public ScriptLevelLog()
{
SubEntries = new List<LogContainer>();
}
[JsonConstructor]
public ScriptLevelLog(LogType logType, string time, string action, string target, string description, int lineNumber) : base(logType, time, action, target, description, lineNumber)
{
SubEntries = new List<LogContainer>();
}
}
在这种情况下,是否有办法避免数据绑定错误,或者我是否需要重新考虑绑定的对象?为HierarchycalDataTemplate(每种类型)设置数据类型。或者忽略这些错误,我想应该是这样简单的事情。谢谢
public class DebugLevelLog : LogContainer
{
public DebugLevelLog()
{
}
[JsonConstructor]
public DebugLevelLog(LogType logType, string time, string action, string target, string description, int lineNumber) : base(logType, time, action, target, description, lineNumber)
{
}
}