views:

317

answers:

3

Hi,

I've got a view

<UserControl x:Class="Modules.NavigationMenu.Views.NavigationMenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<StackPanel>
    <Button Command="{Binding InspectionCommand}">Inspection</Button>
    <Button Command="{Binding HandheldCommand}">Handheld</Button>
</StackPanel>
</UserControl>

and a simple view model - but the commands won't seem to fire - can anyone point me in the right direction please?

public class NavigationMenuViewModel : INavigationMenuViewModel
{
    public INavigationMenuView View { get; set; }

    public NavigationMenuViewModel(IEventAggregator eventAggregator, INavigationMenuView view)
    {
        View = view;
        HandheldCommand = new DelegateCommand<object>(LaunchHandheld);
        InspectionCommand = new DelegateCommand<object>(LaunchInspection);
    }

    private void LaunchInspection(object obj)
    {
        MessageBox.Show("Inspection Clicked");
    }


    private void LaunchHandheld(object obj)
    {
        MessageBox.Show("Handheld Clicked");
    }

    public DelegateCommand<object> HandheldCommand { get; set; }
    public DelegateCommand<object> InspectionCommand { get; set; }

}

My Module just looks like ...

public class NavigationMenuModule : IModule
{
    private readonly IUnityContainer _container;
    private readonly IRegionManager _regionManager;

    public NavigationMenuModule(IUnityContainer container, IRegionManager regionManager)
    {
        _container = container;
        _regionManager = regionManager;
    }

    #region Implementation of IModule

    public void Initialize()
    {
        RegisterViewsAndServices();
        var viewModel = _container.Resolve<INavigationMenuViewModel>();
        _regionManager.Regions[RegionNames.MainMenu].Add(viewModel.View);

    }

    #endregion

    #region Protected Methods

    protected void RegisterViewsAndServices()
    {
        _container.RegisterType<INavigationMenuView, NavigationMenuView>();
        _container.RegisterType<INavigationMenuViewModel, NavigationMenuViewModel>();
    }

    #endregion
}
+1  A: 

Are you sure that the command binding is working? If you run the app and look in the debug output panel, do you see any binding warnings? Perhaps the DataContext of your UserControl isn't set to your NavigationMenuViewModel.

Drew Noakes
A: 

That fixed it. Thank you.

Gareth Evans
There's a little check mark next to his answer. Click that if his answer helped :)
Anderson Imes
A: 

Hi, How did you fix it? I am having the exact same code same class names, I was thinking when did I post it:).

Please share the solution with me.

Thanks, Prema

Prema