Mvvmcross from 4.0 after the plugin of the registration interface to do a refactoring, online examples are not many, here for a reference. This example uses MvvmCross.Plugins.DownloadCache and MvvmCross.Plugins.File.PluginLoader to display a picture on the web.
1,view first to give a uikit.uiimageview to do interface display, named _imageview
2, using NuGet, install Mvvmcross,mvvmcross.plugin.downloadcache,mvvmcross.plugin.file
3,setup code to load plugin, the code is as follows
Public classSetup:mvxiossetup { PublicSetup (Mvxapplicationdelegate appdelegate, Imvxiosviewpresenter presenter):Base(Appdelegate, presenter) {}protected Overrideimvxapplication Createapp () {return NewApp (); }
protected Override voidaddpluginsloaders (Mvxloaderpluginregistry registry) {
Register plugin, must correspond good interface and platform realization Registry. Register<mvvmcross.plugins.downloadcache.pluginloader, mvvmcross.plugins.downloadcache.ios.plugin>(); Registry. Register<mvvmcross.plugins.file.pluginloader, mvvmcross.plugins.file.ios.plugin>(); Base. Addpluginsloaders (registry); } Public Override voidloadplugins (Imvxpluginmanager pluginmanager) {Base. Loadplugins (PlugInManager); Load Plugin pluginmanager.ensurepluginloaded<MvvmCross.Plugins.DownloadCache.PluginLoader>(); pluginmanager.ensurepluginloaded<MvvmCross.Plugins.File.PluginLoader>(); } }
Bindings for 4.View and ViewModel
ViewModel is defined as follows
classTipviewmodel:mvxviewmodel {Private string_imagepath =@"Http://i.imgur.com/VTC3ptT.png"; PublicTipviewmodel () {} Public Override voidStart () {} Public stringTestimagepath {Get=_imagepath; Set= SetProperty (ref_imagepath, Value,"Testimagepath"); } }
View binding Code
Public Partial classTipviewcontroller:mvxviewcontroller<tipviewmodel> { Private ReadOnlyMvximageviewloader _loader; PublicTipviewcontroller ():Base("Tipview",NULL) {_loader=NewMvximageviewloader (() = This. _imageview, () = { }); } Public Override voiddidreceivememorywarning () {Base. Didreceivememorywarning (); //Release Any cached data, images, etc-aren ' t in use. } Public Override voidviewdidload () {Base. Viewdidload (); This. Createbinding ( This. _loader). to<tipviewmodel> (VM =VMs. Testimagepath). Apply (); } }
5, Extra code:
Appdelegate
[Register ("appdelegate")] Public classAppdelegate:mvxapplicationdelegate {//Class-level Declarations Public OverrideUIWindow Window {Get; Set; } Public Override BOOLfinishedlaunching (uiapplication application, Nsdictionary launchoptions) {Window=NewUIWindow (UIScreen.MainScreen.Bounds); varPresenter =NewMvxiosviewpresenter ( This, Window); varSetup =NewSetup ( This, presenter); Setup. Initialize (); varstartup = mvx.resolve<imvxappstart>(); Startup. Start (); Window.makekeyandvisible (); return true; } }View Code
App
Public class app:mvxapplication { publicoverridevoid Initialize () { base . Initialize (); Registernavigationserviceappstart<TipViewModel>(); } }
View Code
How to use the plugin of Mvvmcross in Xamarin.ios