Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the App class.
        /// </summary>
        public App()
        {
            WpfMvvmApplication.Current.Bootstrap();

            var mainModel = new SampleModel("This text is retrieved from the model, which is injected as a named constructor argument to the ViewModel");
            WpfMvvmApplication.Current.Container.Get<IWindowService>().OpenWindow<MainViewModel>(mainModel);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        /// <param name="model">
        /// The model
        /// </param>
        /// <param name="windowService">
        /// The window service
        /// </param>
        /// <param name="messageboxService">
        /// The message box service
        /// </param>
        public MainViewModel(object model, IWindowService windowService, IMessageboxService messageboxService)
        {
            this.windowService = windowService;
            this.messageboxService = messageboxService;
            this.model = (SampleModel)model;

            //// You may expect this to cause a memory leak, without un-registering, but as the Window is closed the entire View Model is automatically unregistered from the Messenger.
            //// You could, of course use this.MessengerInstance.UnRegister() if you needed to do this prematurely for some reason.
            ////
            //// Note: If this View Model is bound to a view other than a WindowView, cleanup will NOT automatically be called when the window is closed; you will have to make you own arrangements.
            //// Personally, I would recommend that if this VM is embedded in a VM that is bound to a PageView, you let the parent view model handle message registrations and pass the actions onto the
            //// child VM by exposing methods. That way, you leverage the automatic clean up that you get for free, and the reduce the risk of leaving an unexpected message registration behind for the lifetime of the app.
            this.MessengerInstance.Register<ShowTextMessage>(this, m => { this.DemoText = m.Text; });

            this.DemoText = "This text is bound to a property on the view model, when you click the button the view model will change the value using the Set() method. This will automatically call RaisePropertyChanged on the property and cause the UI to update.";
        }