2016-10-15 2 views
0

두 개의 컬렉션이있는 클래스가 있고이를 트리에 표시해야합니다.모델 당 두 개의 컬렉션이있는 TreeView

class Test 
{ 
    ObservableCollection<Test> ReplacementOptions {get; set;} 
    ObservableCollection<Test> Given {get; set;} 
    public String Name {get; set;} 
} 

은 지금은 단지 ReplacementOptions 그것을 만드는 방법을 알고

<TreeView Grid.Row="1" x:Name="DefaultEquipmentTreeView" ItemsSource="{Binding SelectedUnit.DefaultEquipment}" PreviewMouseRightButtonUp="OnPreviewMouseRightButtonDown"> 
     <TreeView.ItemTemplate> 
      <HierarchicalDataTemplate ItemsSource="{Binding ReplacementOptions}" > 
       <TextBlock Text="{Binding Name}" /> 
      </HierarchicalDataTemplate> 
     </TreeView.ItemTemplate> 
     <i:Interaction.Behaviors> 
      <xmlEditor:BindableSelectedItemBehavior SelectedItem="{Binding SelectedDefaultEquipment, Mode=TwoWay}" /> 
     </i:Interaction.Behaviors> 
    </TreeView> 

이 어떻게 MVVM와 트리에서 재귀 적으로 모두 컬렉션을 보여주는 달성 할 수있을 것인가?

예 :

당신이 볼 수 있듯이, 각각의 테스트는 테스트의이 컬렉션이 있습니다.

Test1 //Name 
--Replacement //Replacements. for the collection name 
    -- Test2 //Then that lists each Test Name in that collection 
     --Replacements //then that Collection has both Collections... etc 
      --Test4 
     --Given 

--Given // Given 
--Test3 
    --Replacements(empty collection) 
    --Given(empty collection) 
+0

들이 제시 될 것입니다 방법, 순차적으로 또는 조합과 같은 방식으로? – Aybe

+0

게시물을 예제로 업데이트했습니다. – shady

+0

죄송합니다. 제 3 코드 블록으로 머리를 감쌀 수는 없지만 재귀 적으로 보입니다.하지만이 나무가 정확히 당신에게 도움이 되었습니까? – Aybe

답변

0

내 원래의 문제는 해결되지 않지만 해결 방법이 있습니다.

는 트 리뷰를 제거하고 목록보기 사용하기 :

<ListView x:Name="DefaultEquipmentTreeView" ItemsSource="{Binding SelectedUnit.DefaultEquipment}" SelectedItem="{Binding SelectedDefaultEquipment, Mode=TwoWay}" ItemTemplate="{StaticResource EquipmentTemplate}"/> 

[템플릿 :

<DataTemplate x:Key="EquipmentTemplate" DataType="models:Equipment"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition/> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition/> 
     </Grid.RowDefinitions> 

     <TextBlock Text="{Binding Name}" Margin="5,0,0,0"/> 

     <TextBlock Grid.Row="1" Text="Replacement Options:" Margin="10,0,0,0"/> 
     <ListView Grid.Row="2" ItemsSource="{Binding ReplacementOptions}" Margin="15,0,0,0" SelectedItem="{Binding SelectedDefaultEquipment, Mode=TwoWay, Source={StaticResource MainViewModel}}"/> 

     <TextBlock Grid.Row="3" Text="Given:" Margin="10,0,0,0"/> 
     <ListView Grid.Row="4" ItemsSource="{Binding GivenEquipment}" Margin="15,0,0,0" SelectedItem="{Binding SelectedDefaultEquipment, Mode=TwoWay, Source={StaticResource MainViewModel}}"/> 
    </Grid> 
</DataTemplate> 
관련 문제