나는 WPF에서 트 리뷰를 사용하여 다음과 같은 데이터 구조를 시각화하고 싶습니다 :WPF TreeView가 List의 모든 요소를 표시하도록 DataTemplate을 설정하려면 어떻게해야합니까?
class MyDataContext
{
ICollectionView Outers {get;set;}
//...
}
class Outer
{
string Name {get;set;}
IEnumberable<Inner> Actions {get;set;}
}
class Inner
{
string Description {get;set;}
Command OnClick {get;set;}
}
이 지금까지 내 시도는 다음과 같습니다
<!-- DataContext is MyDataContext at this point -->
<TreeView ItemsSource="{Binding Path=Outers}">
<TreeView.Resources>
<DataTemplate DataType="{x:Type myns:Outer}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"/>
<TreeView ItemsSource="{Binding Path=Actions}" >
<DataTemplate DataType="{x:Type myns:Inner}">
<Button Command={Binding Path=OnClick}>
<TextBlock Text="{Binding Path=Description}"/>
</Button>
</DataTemplate>
</TreeView>
</StackPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
내가 얻을 수 있기 때문에이 액세스에 문제가있는 것처럼 그것은 솔기 InvalidOperationException
다음 :
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
나는 예외 (뿐만 아니라 과정없이 버튼)이 없습니다 내부 트 리뷰를 삭제합니다.
나는 당신이 언급 한 웹 사이트를 살펴했지만, 여전히 나는 "외부와 같은 행에있는 버튼과 동작을 얻을 방법을 모른다 "요소. 이 페이지에 제시된 예제는 각 버튼을 "외부"요소 아래의 새 행에 배치합니다. – Onur