У меня есть модель под названием «NodeModel», в которой есть список дочерних узловых моделей.
Код: Выделить всё
public class NodeModel
{
public string Content { get; set; }
public Vector2 Position { get; set; }
public NodeModel ?ParentNode { get; set; }
public List ChildrenNodes { get; }
}
Код: Выделить всё
public class NodeViewModel : ViewModelBase
{
private string _content;
public string Content
{
get
{
return _content;
}
set
{
_content = value;
OnPropertyChanged(nameof(Content));
}
}
private Vector2 _position;
public Vector2 Position
{
get
{
return _position;
}
set
{
_position = value;
OnPropertyChanged(nameof(Position));
}
}
private NodeModel? _parentNode;
public NodeModel ParentNode
{
get
{
return _parentNode;
}
set
{
_parentNode = value;
OnPropertyChanged(nameof(ParentNode));
}
}
public NodeViewModel(NodeModel node)
{
Content = node.Content;
Position = node.Position;
ParentNode = node.ParentNode;
}
}
Мое решение — просто изменить тип списка в NodeModel на NodeViewModel. Но это неправильно, потому что тогда модели не будут должным образом инкапсулированы из ViewModel.
Подробнее здесь: https://stackoverflow.com/questions/787 ... -viewmodel
Мобильная версия