Command not working

Topics: Prism v2 - Silverlight 3
Jul 29, 2009 at 12:55 AM


I am trying to get a command working in a login screen that is displayed prior to displaying the Shell. Here are the various pieces:


            Bootstrapper bootstrapper = new Bootstrapper();



            var view = new LogOnView();

            var presenter = new LogOnPresenter(view);

            Application.Current.RootVisual = view; // Ask the user to log on


        protected override DependencyObject CreateShell()


            presenter = Container.Resolve<ShellPresenter>();

            IShellView view = presenter.View;


            return view as DependencyObject;





        public DelegateCommand<object> LoginCommand { get; private set; }


        public LogOnPresenter(LogOnView view)


            this.View = view;

            view.Model = this;

            this.LoginCommand = new DelegateCommand<object>(

this.Login, this.CanLogin);




        public LogOnPresenter Model


            get { return DataContext as LogOnPresenter; }



                DataContext = value;




<UserControl x:Class="UITest.LogOnView"




    Width="400" Height="300">

    <Grid x:Name="LayoutRoot" Background="White">


            <TextBlock Text="Please log in"/>

            <Button Content="Login"

cal:Click.Command="{Binding LoginCommand}"  />





I have verified that the data context is being set properly. The issue is that my LoginCommand code is not being called when I click on the button.

Any ideas? Any suggestions for how to debug this?

Sorry about the formatting. Pasting from Word does not work very well.

Thank you,


Jul 29, 2009 at 1:44 AM

I don't see it here but I am assuming that the this.Login method conforms to the necessary method signature. One thing you should try is to move your setting of the View.Model to be the very last item in construction.

I seem to remember needing to do this for the data binding to work correctly.

As an FYI, my ViewModel (Presenter) base has the following:

        public ViewModelBase(TView view, IEventAggregator aggregator, IUnityContainer container)
            View = view;
            EventAggregator = aggregator;
            Container = container;

            ViewTitle = "Unknown";




From this you can see that I set the basic items in a particular order and the derived class is responsible for setting the Model = this. I think I have it so I can move that to the base also but it was not a priority yet. 

Jul 29, 2009 at 2:03 PM

Moving the assignment of the Model to last fixed the problem. I understand why but it seems to me that this is pretty stupid and a sign of a poor framework implementation. The order you set the Model should not break functionality. imho

Thank you for the fix.