How to use the plugin of Mvvmcross in Xamarin.ios

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.