我正在阅读here中的代码。我在TreeList.cs中找到了private ITreeModel _model;
:
namespace Aga.Controls.Tree
{
public class TreeList: ListView
{
#region Properties
//...
private ITreeModel _model;
public ITreeModel Model
{
//...
}
//...
}
}
ITreeModel是ITreeModel.cs中的接口:
namespace Aga.Controls.Tree
{
public interface ITreeModel
{
/// <summary>
/// Get list of children of the specified parent
/// </summary>
IEnumerable GetChildren(object parent);
/// <summary>
/// returns wheather specified parent has any children or not.
/// </summary>
bool HasChildren(object parent);
}
}
_model
是实例化的对象吗?编辑:
TreeList.cs
:namespace Aga.Controls.Tree
{
public class TreeList: ListView
{
#region Properties
/// <summary>
/// Internal collection of rows representing visible nodes, actually displayed in the ListView
/// </summary>
internal ObservableCollectionAdv<TreeNode> Rows
{
get;
private set;
}
private ITreeModel _model;
public ITreeModel Model
{
get { return _model; }
set
{
if (_model != value)
{
_model = value;
_root.Children.Clear();
Rows.Clear();
CreateChildrenNodes(_root);
}
}
}
private TreeNode _root;
internal TreeNode Root
{
get { return _root; }
}
//....
}
}
}
编辑2:
某处:
public partial class RegistrySample : UserControl
{
public RegistrySample()
{
InitializeComponent();
_tree.Model = new RegistryModel();
}
}
class RegistryModel : ITreeModel
最佳答案
当然可以做到这一点,但是基础对象必须实现此接口。所以你可以做类似的事情
ITreeModel _model = new TreeModel();
哪里
public class TreeModel:ITreeModel
{
...
}