Hi,
I have a view model that has a command and also a menu interface that points to another class that builds the menu:
private RelayCommand _test; public ICommand TESTCommand { get { if (_test == null) { _test = new RelayCommand(SomeMethod); } return _test; } }
private IMenu _menu; public IMenu MainMenu { get { return _menu; } set { _menu = value; OnPropertyChanged(() => this.MainMenu); } }
The class:
public class Menu: IMenu { public ObservableCollection<ToolbarItemModel> FileItems { get; set;} public Menu() { FileItems = new ObservableCollection<MenuItemModel>(); FileItems.Add(new MenuItemModel() { Content = "Settings", IsVisible = true, IsEnabled = true, KeyGesture = "" }); FileItems.Add(new MenuItemModel() { Content = "Exit", IsVisible = true, IsEnabled = true, KeyGesture = "Ctrl+X" }); } }
I want to be able to add a property on the MenuItemModel i.e.
public string CommandName { get; set;}
This would then change the fileItems to:
FileItems.Add(new MenuItemModel() { Content = "Settings", IsVisible = true, IsEnabled = true, KeyGesture = "", CommandName="TESTCommand" });
Want to be able to run the TestCommand that is on the view model by just passing through the name of the command, I can access this if I pass through the viewmodel to the Menu Class but don't to do it this way..
Not sure if this can be done by simply passing through the name of the command..
Any ideas on how to bind to the command by just using the name using xaml?