2012-12-07 3 views
0

나는 주소, 부모의 계층 템플릿을 생성계층 적 데이터 템플릿 <AnotherObject>

public class Parent 
{ 
    public string Name {get; set;} 
    public int ID {get; set;} 
    public List<Child> Children{set; get;} 
    public Address HomeAddress {get; set;} 
} 

이 구조와 객체를 가지고있는 ObjectToObservableListConverter

어린이
public class ObjectToObservableListConverter : IValueConverter 
    { 

     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      if (value != null) 
      { 
       return new ObservableCollection<Graphic> { (value as Graphic) }; 
      } 
      return null; 
     } 


     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      throw new NotImplementedException(); 
     }  

    } 

PropertyToListConverter

public class PropertyToListConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      Type type = value.GetType(); 
      PropertyInfo[] propertyList = value.GetType().GetProperties(); 
      List<object> values = 
       (from property in propertyList 
       //where property.GetCustomAttributes(typeof(NotForTreeViewAttribute), false).Count() == 0 
       select property.GetValue(value, BindingFlags.Default, null, null, CultureInfo.InvariantCulture)).ToList(); 
      return values; 

     } 

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      throw new NotImplementedException(); 
     } 
    } 

는 내가 만든 템플릿은 다음과 같습니다 : 나는 부모 에 템플릿을 생성하고 어린이 재산권의 ItemsSource 경로를 설정하면

<TreeView ItemsSource="{Binding Path=Parent, 
              Converter={StaticResource ResourceKey=objectToListConverter}, 
              UpdateSourceTrigger=PropertyChanged}"> 
      <TreeView.Resources> 

    <HierarchicalDataTemplate DataType="{x:Type en:Parent}" 
                ItemsSource="{Binding Path=Children}"> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Margin="0,4,0,0" 
              VerticalAlignment="Center" 
              FontWeight="Bold" 
              Text="Children" /> 
         </StackPanel> 
        </HierarchicalDataTemplate> 
        <HierarchicalDataTemplate DataType="{x:Type en:Child}" 
                ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}"> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Margin="0,4,0,0" 
              VerticalAlignment="Center" 
              FontWeight="Bold" 
              Text="{Binding Path=ChildName}" /> 
         </StackPanel> 
        </HierarchicalDataTemplate> 
        <HierarchicalDataTemplate DataType="{x:Type en:Address}" 
                ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}"> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Margin="0,4,0,0" 
              VerticalAlignment="Center" 
              FontWeight="Bold" 
              Text="AddressType" /> 
         </StackPanel> 
        </HierarchicalDataTemplate> 

</TreeView.Resources> 
</TreeView> 

, 나는 부모의 나머지 속성을하지 않습니다. ItemsSource를 부모 및 사용자 속성 유형의 속성으로 설정하면 변환기 목록을 표시 할 때 자식 계층 구조가 표시되지 않습니다.

무엇이 누락 되었습니까?

도와주세요. 미리 감사드립니다.

답변