私は xaml でバインドした親を持つ Node オブジェクトを持っています。
<Label>
<Hyperlink>
<TextBlock Text="{Binding Path=Node.Parent.Name}"/>
</Hyperlink>
</Label>
私のViewModelは次のようになります
public class NodeViewModel
{
public Node Node { get; set; }
public NodeViewModel(Node model)
{
Node = model;
if(model.Parent != null) { } // Check if it's null, then do nothing.
// When the above line is commented out, my label displays nothing.
}
}
if ステートメントをコメントアウトすると、ラベル/テキストブロックが空白になるのはなぜですか? 私は何か間違ったことをしていますか?オブジェクトが null かどうかを確認するまで、オブジェクトは存在し、存在しませんか?
編集:
言い忘れましたが、私のノード クラスは非常にシンプルでINotifyPropertyChanged
、Name プロパティを実装しています。
2 番目の編集:私の単純な Node クラスを追加しました。
[ImplementPropertyChanged] // From Fody.PropertyChanged
public class Node
{
public int? ParentID { get; set; }
public Node Parent { get; set; }
public string Name { get; set; }
public Node Node(Node p = null)
{
Parent = p;
}
}