Hello,
I am creating a menu and binding the menu items ate runtime as follows but I am not able to make it work.
I am creating the menu as follows:
Menu menu = new Menu();
menu.Items.Add(new MenuItem { Command = new PackCommand(), Header = "Pack" });
DockPanel.SetDock(menu, Dock.Top);
content.Children.Add(menu);
And I am implementing ICommand:
public static class PackCommand : ICommand {
Boolean CanExecute(object parameter) {
return true;
}
void Execute(object parameter) {
Packer packer = new Packer();
packer.Run();
}
}
- I am not sure how to bind the menu item.
- Why CanExecute? Shouldn't it always? I only want to run packer.Run when the buttom is clicked.
I think I should implement ICommand but I am not even sure I should do this?
Could someone please help me out?
Thanks, Miguel