/// <summary> /// 数据库模型 /// </summary> public class Database { public string name = "master";//数据库名称 //表集合 public List<Tables> tables = new List<Tables>(); //视图集合 public List<Views> views = new List<Views>(); } public class Tables { public string name { get; set; } } public class Views { public string name { get; set; } }
怎么绑定这个 ViewModel 到 WPF TreeView ?
public class ViewModel { //数据库集合 public IList<Database> vwModel { get { List<Database> Model = new List<Database>(); Database db = new Database(); //添加表 db.tables.Add(new Tables() { name = "Table1" }); db.tables.Add(new Tables() { name = "Table2" }); db.tables.Add(new Tables() { name = "Table3" }); db.views.Add(new Views() { name = "Views1" }); db.views.Add(new Views() { name = "Views2" }); db.views.Add(new Views() { name = "Views3" }); Model.Add(db); return Model; } } }
类似于
treeView.DataContext