RelayCommand not firing on MenuItem click WPF MVVM?

Up vote 1 down vote favorite share g+ share fb share tw.

I have menu item on my WPF form that runs a import routine, I have bound the command property to a ICommand property in my view model but for some reason the method won't fire. This is the xaml: Import And this is in my view model: private ICommand importfilecommand; public ICommand ImportFileCommand { get { if (this. Importfilecommand == null) { this.

Importfilecommand = new RelayCommand(parm => ImportFile()); } return this. Importfilecommand; } } private void ImportFile() { OpenFileDialog dialog = new OpenFileDialog(); dialog. Filter = "Tab Files (*.

Tab)|*. Tab*"; if (dialog.ShowDialog() == true) { // MessageBox. Show(dialog.

FileName); } } This is the pattern that I have used for all my buttons on the form but the menu item just won't work. Am I missing something or does menu items have to be done differently? Thanks.

C# wpf mvvm menuitem link|improve this question asked Dec 21 '09 at 22:35Nathan W9,20052874 64% accept rate.

That part is not clear from the question. Otherwise it looks good. – Jobi Joy Dec 21 '09 at 22:50 Yeah if I set a break point on the ImportFileCommand the RelayCommand is getting newed up but it just doesn't want to fire.

– Nathan W Dec 21 '09 at 22:53.

Change your XAML to In your example, the "Import" content of the MenuItem element implicitly creates a child MenuItem of the parent File MenuItem. This child MenuItem has no Command property defined and so is unable to be executed. Apparently the executability of the Command defined on the parent MenuItem is overridden by the sub-menu expansion functionality.

I can't believe I looked over that. – Nathan W Dec 22 '09 at 22:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions