Quote:
|
Like DricuS I was going to try my hand at contributing to MP, but when I found out that there wasn't even an API between the core and the skin I backed off.
|
In MP-II we try to keep the skin (GUI) and logic (plugins & models) completely seperated
That is:
- the skinengine does not know about any plugins or models
- the plugins and models dont know about any gui
The advantage here is that:
1) you can use any behaviour from any model in any GUI screen ,
example show weather info on the home-menu
2) We can easily extend skinengines without breaking the plugins & models
3) We can even switch skinengines (like we do now with the new WPF engine) without breaking the plugins
4) It gives much more freedom to skinners
This is the reason why you dont see a pre-defined API between the skin and the plugins/models.
The skinengine uses databinding to databind to properties and collections which are provided by the plugins/models.
And for executing commands, the skinengine uses reflection to do it.
So using the skinengine you can:
- databind your GUI controls to any property or collection exposed by plugins/models
- databind your GUI controls to any property or collection exposed by the core
- let the GUI call any method on your model using commands
- let the GUI call any method on the core using commands
An example how this is done in the new WPF engine:
Databinding:
Code:
<Canvas xmlns:local="clr-namespace:Model;assembly=mymovies">
...
<ListView ... ItemsSource="{Binding Movies}" ... />
...
</Canvas>
The first line imports an plugin (mymovies.dll in this case)
finds & instansiates the
Model class from it
and sets the instance of the
Model class it into the Context of the canvas
The second line draws a list view where the items in the listview are databound.
The databinding is set the the
Movies property and since the Context of the canvas is set to
mymovies.Model the complete databinding will be set
to
public IEnumerable mymovies.Model.Movies {get;} property
As long as this property returns an
IEnumerable the listview will be able to draw the items
(Note that for a ListView the model will usually return an
ItemsCollection which is a class defined in the Core
This class simply holds a collection of
ListItem and can send events when the collection changes so the skinengine can
update its databinding and refresh the listview )
Commands:
Code:
<ListView ... Command="{Binding Path=Select}" CommandParameter="{Binding Path=this.CurrentItem}" .../>
Here we setup a command using the same principle as above
When you click on an item in the listview, it will call:
public mymovies.Model.Select( ListItem currentItem)
The movies model will handle the select and might for
example update its
Movies property if you are browising your movies folder.
As you can see no interfaces are needed between the skinengine & plugins/models
because of the databinding & command architecture.
Frodo