我的树木观对Model级有正确的约束力,但我会有一些带孩子的“东京会议”的班轮,我不得不获得我的过急模板,以正确开展工作。
预 收
页: 1
<TreeView.Resources>
<!-- HierarchicalDataTemplate for ClassModel -->
<HierarchicalDataTemplate DataType= "{x:Type models:ClassModel}" ItemsSource = "{Binding Path=ChildClasses}">
<TextBlock Text="{Binding Path=ClassName}"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type models:CADModel}">
<TextBlock Text="{Binding Path=PartNumber}"/>
</DataTemplate>
</TreeView.Resources>
public interface IClassModel : ITreeNode
{
ObservableCollection<ClassModel> ChildClasses { get; set; }
ObservableCollection<CADModel>? CADModels { get; set; }
int ClassId { get; set; }
int ParentClassId { get; set; }
string ClassName { get; set; }
bool HasChildClass { get; set; }
LibraryModel? ParentLibrary { get; set; }
}
public class ClassModel : TreeNode, IClassModel
{
public LibraryModel? ParentLibrary { get; set; } = null;
public int ParentClassId { get; set; } = 0;
public int ClassId { get; set; } = 0;
public string ClassName { get; set; } = string.Empty;
public bool HasChildClass { get; set; } = false;
public ObservableCollection<ClassModel> ChildClasses { get; set; } = new ObservableCollection<ClassModel>();
public ObservableCollection<CADModel>? CADModels { get; set; } = null;
public ClassModel()
{
if (HasChildClass == false)
{
CADModels = new ObservableCollection<CADModel>()
{
new CADModel()
{
Id = 0,
PartNumber = "Bob",
Revision = "A.1"
}
};
}
}
}
public interface ICADModel : ITreeNode
{
string PartNumber { get; set; }
string Revision { get; set; }
}
public class CADModel :TreeNode, ICADModel
{
public string PartNumber { get; set; } = string.Empty;
public string Revision { get; set; } = string.Empty;
}
I was expecting that i would see one CADmodel leaf called "Bob" below every ClassModel node