0

以下のコードでは、ツリービューにデータが取り込まれません。誰が私が間違っているかを見ることができますか?

ありがとう

public class FouList
{
  public string Source { get; set; }
  public List<FouData> ListOfFou { get; set; } 
}

 public struct FouData
{
   public string Name { get; set; }
}

<Window.Resources>
 <HierarchicalDataTemplate DataType="{x:Type local:FouList}"
                              ItemsSource="{Binding Path=ListOfFou}">
    <Border BorderBrush="Black"
                BorderThickness="2"
                CornerRadius="10">            
            <TextBlock Margin="10,0,0,0"
                           Text="{Binding Source}"></TextBlock>

    </Border>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:FouData}">
    <Border BorderBrush="Black"
                BorderThickness="2"
                CornerRadius="10">           
            <TextBlock Margin="10,0,0,0"
                           Text="{Binding Name}"></TextBlock>               

    </Border>
</HierarchicalDataTemplate>
</Window.Resources>


<TreeView Margin="26,0,35,12" Name="treeView1" Height="298"
   ItemsSource="{Binding Path=FouList}" VerticalAlignment="Top"/>

FouList FL = new FouList();
//code to populate FL
//I've debugged and can see it populating correctly
treeView1.DataContext = FL;
4

2 に答える 2

1

ItemsSourceのバインディングtreeView1が正しくありません。ListOfFouにバインドするのではなく、プロパティにバインドするつもりだと思いますFouList

<TreeView Margin="26,0,35,12" Name="treeView1" Height="298"
          ItemsSource="{Binding Path=ListOfFou}" VerticalAlignment="Top"/>
于 2010-11-20T15:39:35.823 に答える
0

私はあなたのどちらかを変更しようとします

List<FouData> ListOfFou  { get; set; } 

ObservableCollection<FouData> ListOfFou { get; set; }

または変更を伝播する NotifyPropertyChanged("ListOfFou");

于 2010-11-20T15:32:12.197 に答える