我想"翻译"我之前的Forms-Application到WPF解决方案试图遵循MVVM模式。
现在我正面临着我想要构建一个"背景敏感的问题" Contextmenu - 我不知道如何开始。
这是Forms-Application中用于生成层次结构和Contextmenus的代码:
_tvLocation.Nodes.Clear();
foreach (Data.Location location in LocationManager.GetAll(this.DataSource)) {
TreeNode parent = new TreeNode(location.Name) {
Tag = location,
ContextMenu = new ContextMenu(new MenuItem[] {
new MenuItem("Standort löschen", new EventHandler(DelLocation_Click)) {
Tag = location
},
new MenuItem("Raum hinzufügen", new EventHandler(AddRoom_Click)) {
Tag = location
}
})
};
foreach (Data.Room room in location.GetChildren(DataSource)) {
TreeNode child = new TreeNode(room.Name) {
Tag = room,
ContextMenu = new ContextMenu(new MenuItem[]{
new MenuItem("Raum löschen", new EventHandler(DelRoom_Click)){
Tag = room
},
new MenuItem("Schrank hinzufügen", new EventHandler(AddLocker_Click)){
Tag = room
}
})
};
foreach (Data.Locker locker in room.GetChildren(this.DataSource)) {
TreeNode gradChild = new TreeNode(locker.Name) {
Tag = locker,
ContextMenu = new ContextMenu(new MenuItem[]{
new MenuItem("Schrank löschen", new EventHandler(DelLocker_Click)){
Tag = locker
}
})
};
child.Nodes.Add(gradChild);
}
parent.Nodes.Add(child);
}
_tvLocation.Nodes.Add(parent);
}
_tvLocation.ExpandAll();
有没有办法在WPF中构建类似的东西? (当然有 - 有人可以给我一个暗示吗?)