delegateCommand is not executing on menuitem.

Topics: Prism v4 - Silverlight 4
Jul 22, 2012 at 9:52 PM

Hi friends out there.

In My Prism MVVM applicatin i have bind property with commar of menuitem  but it is not working.Below is my code of view and viewmodel.

This is my view code:

        <toolkit:MenuItem  Header="Home"  Width="Auto" Height="24"  VerticalAlignment="Top" Command="{Binding Path=__showcommand}" />

 

This is corresponding viewmodel code:

 public class test1: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public ICommand _showcommand{set;get;}
        public FamilyTreeMenuBarViewModel()
        {
            this._showcommand = new DelegateCommand(showmessage);
        }

        public void showmessage()
        {
            MessageBox.Show("clicked");
        }
    }

but when i am clicking on this menu .This command execute function is not working.So if there is something wrong in code please let me know and make it clear why we need to do that.

Thanks in advance

Developer
Jul 23, 2012 at 5:20 PM

Hi,

After checking the code snippets you posted, I found a typo that could be the cause behind this problem. Although it's difficult to see, in the biding of the view showcommand has two underscores, while in the view model it only has one underscore. Therefore, the binding is not working because the name in the menu item's binding is different than the one in the view model.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Jul 24, 2012 at 2:20 AM

Thanks for reply.

I figure out  the problem which i had in my code.

Regards

Pankaj Goswami