1

以下に示すように、ペイロードを持つ 2 つの多対多エンティティがあります。

エンティティのスナップショット

したがって、部品番号: で MasterPartNumber に格納されたAssemblyを作成するには、関係: によって与えられる MasterPartNumber.pnナビゲーション プロパティ を使用します。これにより、その親アセンブリの下にあるすべての子 pnID が得られます。ParentBOMsMasterPartNumber.pnID = MasterPartsList.parentPnID

そのアセンブリの子部品番号を取得するにはChildPn、 で定義されたナビゲーション プロパティを使用しMasterPartsList.pnID = MasterPartNumber.pnIDます。

最上位のアセンブリ アイテムは MasterPartsList にリストされないことに注意してください (これらのアイテムの parentPnID は null になります)。

私の TreeView HierarchicalDataTemplate バインディングは次のとおりです。

<TreeView x:Name="AssemblyTreeView"
          ItemsSource="{Binding BOMItems}">
  <TreeView.ItemTemplate>
    <HierarchicalDataTemplate DataType="{x:Type local:MasterPartNumber}"
                              ItemsSource="{Binding ParentBOMs.ChildPn}">
      <TextBlock Text="{Binding pn}" />
    </HierarchicalDataTemplate>
  </TreeView.ItemTemplate>
</TreeView>

私は正しいと信じています。デバッガーをステップ実行すると、子情報を持つ各アイテムの BOMItem ナビゲーション プロパティ全体 (ParentBOM.ChildPn.pn) が設定されていることがわかります。

これらの子プロパティが TreeView に入力されているのを確認できないのはなぜですか?!

What I should get:

Root Assembly
--Sub Assembly
----Sub Assembly
------Child (n-levels deep)

私が実際に得るもの:

Root Assembly

追加のコンバーターが必要ですか? ObservableCollection オブジェクト ラッパーの「ゲッター」をさらに定義する必要がありますか?

Known possible sources of the problem:
1. Entity Framework is lazy loading, and just hasn't loaded the navigation properties I see in
   the debugger being populated. (No, set LazyLoading to false.)
2. My HierarchicalDataTemplate isn't probing for children just on the fact that it has children
   -- aka it only understands to switch the binding path when a new DataType is available, or 
   something like that. (Not likely, because I've seen HierarchcialDataTemplates for self-referencing entities of a single entity type.)

What I have right:
1. I can cascade down the binding route I told my TreeView to take in the debugger. 
    Parent `pn` is populated as well as its `ParentBOMs.ChildPn.pn`. 

助けてください!ありがとうございました !

4

1 に答える 1

0

予想される出力がどうあるべきかについての考えを得ることができませんか? ツリーを描いて投稿していただけますか。

表示するドメイン タイプのラッパー VM タイプを作成する必要がある場合があります。言う..MasterPartVM。2 つのルート (例: Children) のロジックを使用してプロパティを定義できるようになりました。階層データ テンプレートは、このプロパティを使用して常に次のレベルに展開されます。

これにより、MasterPartVM.Children の実装に適切な子を見つける責任が生じます。これは、あなたが突き止めたようです。問題を誤解している場合はお知らせください..

たとえば、リンクされた投稿では、ラッパー プロパティを使用してサブグループとエントリを結合し、1 つのリストを照合していることがわかります。

ここに別の例があります

public class MyPart
    {
        public string Name { get; set; }
        public bool IsRoot { get; set; }
        public string[] ChildNames { get; set; }
        public IList<MyPart> Children { 
            get {
                if (IsRoot)
                    return ChildNames.Select(c => new MyPart { Name = c, ChildNames =new[]{c} }).ToList();
                else
                    return new List<MyPart>{new MyPart { Name = "No more children" }};
        } }
    }

MyPartsCollection = new ObservableCollection<MyPart>();
            MyPartsCollection.Add(new MyPart
            {
                Name = "Root1",
                IsRoot = true,
                ChildNames = new []{"Item1", "Item2", "Item3"}
            });
<TreeView ItemsSource="{Binding MyPartsCollection}">
  <TreeView.ItemTemplate>
    <HierarchicalDataTemplate DataType="{x:Type local:MyPart}"
                              ItemsSource="{Binding Children}">
      <TextBlock Text="{Binding Name}" />
    </HierarchicalDataTemplate>
  </TreeView.ItemTemplate>
</TreeView>
于 2013-04-22T13:42:32.683 に答える