我正在使用TreeView
WPF
我有以下课程:
class MyFiles : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string displayName;
public string fullPath;
public string DisplayName
{
get{return displayName;}
set{displayName = value; INofityPropertyChanged();}
}
public string FullName
{
get{return fullPath;}
set{fullPath = value; INofityPropertyChanged();}
}
private void INofityPropertyChanged(string propertyName="")
{
if(propertyName != null && PropertyChanged != null)
PropertyChanged (this, new PropertyChangedEventsArgs(propertyName);
}
}
我想将类绑定到TreeView
我尝试了什么:
<TreeView Name=treeViewFiles>
<TreeView.Resources>
<HierarcjocalDataTemplate DataType="x:Static local:MyFiles" ItemSource="{Binding MyFiles}">
<StackPanel Orientation="Horizontal">
<TextBlock Text={Binding DisplayName}>
<TextBlock Text={Binding FullName}>
</StackPanel>
</HierarcjocalDataTemplate>
<TreeView.Resources>
</TreeView>
的.cs:
fileList = new ObservableCollection<MyFiles>();
fileList.Add(new MyFiles("Test","TestPath"));
treeViewFiles.ItemSource = fileList;
我得到的东西就像一个列表而不是树:\\ 我如何修复我的代码以获得一个真正的树与root等? 谢谢!