Question

I'm a newcommer in Caliburn.

I have a couple of questions of MVVM and Caliburn.

  1. How can a view invoke a method explicitly on a ViewModel? Caliburn invokes a ViewModel constructor first. So if it is, then where the instance is going to be contained? The code inside my View create a new instance at the moment (I need to invoke a method on ViewModel explicitly). But regarding that ViewModel should be instantiated already, this is silly.

  2. How can I force a binding update on the UI thread?

Was it helpful?

Solution

Caliburn.Micro has the concept of actions to invoke verbs on your view models from the view. You can largely use conventions for this, so for example if you have a Button in your view with x:Name="Save", then your Save method on the view model will be invoked when the Button is clicked.

You can always use explicit bindings to override the conventions, as well as providing your own conventions, and Caliburn.Micro also provides attached properties to associate view model methods to events in the view.

In terms of forcing a UI update, your view models will implement INotifyPropertyChanged, and Caliburn.Micro provides base implementations of this, including PropertyChangedBase, and Screen (which adds life cycle).

You can then use the Caliburn.Micro supplied helper method to invoke the PropertyChanged event. This is called NotifyOfPropertyChange, and it can take an expression lambda to specify which property to notify, rather than using a magic string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top