MVVMCross中的自定义插件 [英] Custom plugin in MVVMCross

查看:135
本文介绍了MVVMCross中的自定义插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MVVMCross v3上工作,我想创建自己的插件,我遵循了本教程(适用于vNext)

I'm working on MVVMCross v3 and I want to create my own plugin, I followed this tutorial (which is for the vNext)

http://slodge.blogspot.fr/2012/10/build-new-plugin-for-mvvmcrosss.html

为了与v3兼容,我将IMvxServiceConsumer和GetService更改为Mvx.Resolve.

To be compatible for the v3 I changed IMvxServiceConsumer and GetService to Mvx.Resolve.

但是在本教程中有:

然后,对于WinRT,WindowsPhone和MonoTouch客户端,还需要在setup.cs中提供一个Loader访问器,例如:

Then, for WinRT, WindowsPhone and MonoTouch clients, you also need to provide a Loader accessor in setup.cs - like:

protected override void AddPluginsLoaders(Cirrious.MvvmCross.Platform.MvxLoaderPluginRegistry loaders)

{
    loaders.AddConventionalPlugin<MyCompany.MvvmCross.Plugins.Mega.WindowsPhone.Plugin>();

    base.AddPluginsLoaders(loaders);
}

如何在v3中做到这一点?

How can I do that in v3?

谢谢

推荐答案

如果要编写新插件,则:

If you want to write a new plugin, then :

  • the up-to-date sample is https://github.com/slodge/MvvmCross-Tutorials/tree/master/GoodVibrations
  • there are some notes on this sample in https://speakerdeck.com/cirrious/plugins-in-mvvmcross

对于插件初始化,nuget软件包现在通过引导文件执行此操作-例如在以下位置查看为位置添加的文件:

For plugin initialisation, the nuget packages now do this via bootstrap files - e.g. see the files added for Location at:

  • (WinRT, WinPhone, Droid) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Droid/Bootstrap/LocationPluginBootstrap.cs
  • (Touch) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Touch/Bootstrap/LocationPluginBootstrap.cs

引导程序方法是现在进行初始化的常规方法.

The bootstrap way is the normal way to do initialisation now.

如果您确实想使用非引导技术,则可以执行以下操作:

If you did want to use a non-bootstrap technique then you can do this:

  • 在WinRT,WinPhone和Droid中,您不需要使用加载程序,但是在使用插件之前,您需要先调用MyPlugin.PluginManager.Instance.EnsureLoaded.
  • 在Touch中,您需要在protected override void AddPluginsLoaders(MvxLoaderPluginRegistry loaders)-期间提供一个加载程序,并且然后您仍然需要调用EnsureLoaded()才能使用该插件.
  • In WinRT, WinPhone, and Droid, you don't need to use a loader, but you do need to call MyPlugin.PluginManager.Instance.EnsureLoaded before the plugin can be used.
  • In Touch, you would need to provide a loader during protected override void AddPluginsLoaders(MvxLoaderPluginRegistry loaders) - and you'd then still need to call EnsureLoaded() before the plugin can be used.

有关这种旧方式"工作的示例,请参见

For examples of this 'old way' of working, see Setup.cs in the UI projects in https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20TwitterSearch

这篇关于MVVMCross中的自定义插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆