0

I started to learn Caliburn.Micro with UWP. first, I found a good example at here. https://github.com/IanSavchenko/BleLab ( Thank you, Ian )

enter image description here

This application has BumbugerMenu + Caliburn.Micro. in this project, BumbergerMenu root is "Main". and Sub menu is "About","Setting","Device". My Quesiton is .. How to write "ViewModel" as Normal.

First is "MainViewModels" The class is extend with "Conductor"

sub Menu "AboutViewModel" The class is extend iwth "PropertyChangedBase"

sub Menu "DeviceViewModel" The class is extend with Conductor, IHandle

Q1 : When should I use "Conductor" instead of "PropertyChangedBase"

Q2 : in MainViewModel, Why can the class "MainViewModel" expect this arguments when initialize ? I read manual of Caliburn.Micro, but I can not understand why..

public MainViewModel(
           DeviceShellViewModel deviceShellViewModel, 
           AboutViewModel aboutViewModel, 
              SettingsViewModel settingsViewModel)
       {
           _deviceShellViewModel = deviceShellViewModel;
           _aboutViewModel = aboutViewModel;
           _settingsViewModel = settingsViewModel;
           ActivateItem(_deviceShellViewModel);
       }

DeviceModel constructor has different arguments.. Wow. I can not understand it.

public DeviceViewModel(DeviceInfo deviceInfo)
        {
            _commandRunner = IoC.Get<CommandRunner>();
            _eventAggregator = IoC.Get<IEventAggregator>();
            _deviceInfo = deviceInfo;
        }
Kazuhiko Nakayama
  • 801
  • 1
  • 8
  • 24

1 Answers1

2

For your first question:

PropertyChangedBase – Implements INotifyPropertyChangedEx (and thus INotifyPropertyChanged). It provides a lambda-based NotifyOfPropertyChange method in addition to the standard string mechanism, enabling strongly-typed change notification. Also, all property change events are automatically marshaled to the UI thread.2

In Caliburn.Micro, this role is represented by the IConductor interface which has the following members: ActivateItem – Call this method to activate a particular item. It will also add it to the currently conducted items if the conductor is using a “screen collection.” DeactivateItem – Call this method to deactivate a particular item. The second parameter indicates whether the item should also be closed. If so, it will also remove it from the currently conducted items if the conductor is using a “screen collection.” ActivationProcessed – Raised when the conductor has processed the activation of an item. It indicates whether or not the activation was successful.3 GetChildren– Call this method to return a list of all the items that the conductor is tracking. If the conductor is using a “screen collection,” this returns all the “screens,” otherwise this only returns ActiveItem. (From the IParent interface) INotifyPropertyChangedEx – This interface is composed into IConductor.

So basically the most important part is that the Conductor allows you to load a specific view, at a specific time (navigation/view injection). Source of the quotes: https://caliburnmicro.codeplex.com/wikipage?title=Screens,%20Conductors%20and%20Composition

Regarding your second question:

The constructor of MainViewModel requires the instances of the VMs from IoC so that the navigation can be performed by the Conductor through ActivateItem( as stated in my aswer from Q1). And regarding the part with "DeviceModel constructor has different arguments"...that is natural; every VM has specific responsibilities and in order to be able to fulfill them it needs specific objects.

Hope this helps. If you have any other questions I'll do my best to address them.

Paul
  • 61
  • 5
  • Thank you, Paul. with your answer, I will start to learn more... Now, I understand 60% yet. I will keep learning.. Someday, .. be 100% : ) – Kazuhiko Nakayama Jul 25 '17 at 11:26