2013-02-11 1 views
0

I 내 ​​TreeView에 데이터를로드 할 수없는 곳에서이 문제가 발생하지만 대신 수동으로해야합니다. 내 정적 솔루션은 다음과 같습니다 : 당신이 키우면에게 세 개의 수준을 볼 수 있고 내가 수준의 동적 양을 wan't로TreeView의 동적 ObservableCollection?

public static ObservableCollection<ClassOfDoom> GetAll() 
    { 
     ObservableCollection<ClassOfDoom> listToReturn = new ObservableCollection<ClassOfDoom>(); 

     ClassOfDoom treeItem = null; 

     OUViewModel ouvm = new OUViewModel(); 
     int[] tempOU = ouvm.HierarchyIntOU; 
     int[] tempP = ouvm.HierarchyIntParent; 

     treeItem = new ClassOfDoom("Root"); 
     treeItem.cID = tempOU[0]; 
     treeItem.pID = tempP[0]; 
     for (int i = 0; i < ouvm.HierarchyIntParent.Length; i++) 
     { 
      if (treeItem.cID == tempP[i]) 
      { 
       treeItem.ClassOfDooms.Add(new ClassOfDoom(tempOU[i].ToString())); 
       treeItem.ClassOfDooms.Last().pID = tempP[i]; 
       treeItem.ClassOfDooms.Last().cID = tempOU[i]; 
       for (int i1 = 0; i1 < ouvm.HierarchyIntParent.Length; i1++) 
       { 
        if (treeItem.ClassOfDooms.Last().cID == tempP[i1]) 
        { 
         treeItem.ClassOfDooms.Last().Countries.Add(new ClassOfDoom(tempOU[i1].ToString())); 
        } 
       } 
      } 
     } 
     listToReturn.Add(treeItem);  
     return listToReturn; 
    } 

이 있지만 작동합니다. 누군가가 내 ClassOfDooms을 궁금해하는 경우 목록은 다음과 같습니다

public ObservableCollection<ClassOfDoom> ClassOfDooms 
{ 
    get 
    { 
     if (classOfDooms == null) classOfDooms = new ObservableCollection<ClassOfDoom>(); 
     return classOfDooms; 
    } 
    set { classOfDooms = value; } 
} 

나는 내 데이터베이스 또는 아무것도 같은 데이터를 읽는 아무 문제가 없다는 것을 다시 언급하고자합니다. TreeView는 모든 정보가 아니라 올바른 정보를 얻습니다.

EDIT : I는 다음과 같이 자신을 해결 :

ClassOfDoom[] asdfDooms = new ClassOfDoom[ouvm.HierarchyIntParent.Length]; 
    for (int i = 0; i < ouvm.HierarchyIntParent.Length; i++) 
    { 
     asdfDooms[i] = new ClassOfDoom(); 
     asdfDooms[i].cID = tempOU[i]; 
     asdfDooms[i].pID = tempP[i]; 
     asdfDooms[i].name = tempPersonName + asdfDooms[i].cID.ToString(); 
    } 
    for (int aint = 0; aint < ouvm.HierarchyIntParent.Length; aint++) 
    { 
     for (int i = 0; i < ouvm.HierarchyIntParent.Length; i++) 
     { 
      if (asdfDooms[aint].cID == asdfDooms[i].pID) 
      { 
       asdfDooms[aint].classOfDooms.Add(asdfDooms[i]); 
      } 
     } 
    } 
    listToReturn.Add(asdfDooms[0]); 

답변

0

HierarchicalDataTemplate 제어와 연계하여 INotifyPropertyChanged interface 구현 시도이 내부 데이터 구조의 변경은 트 리뷰 구조에 반영되도록한다.

+0

나는 INotifyPropertyChanged 인터페이스를 빠르게 보았지만 코드에서 어떻게 구현할 수 있는지 이해하지 못했습니다. 예를 들어 줄 수 있습니까? 더 많은 정보가 필요하십니까? –

+0

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx에서 필요한 이유와 사용 위치에 대해 약간의 배경 지식을 제공합니다. –