在MvvmCross monodroid活动内插入Monogame视图 [英] Insert a Monogame view inside MvvmCross monodroid Activity

查看:81
本文介绍了在MvvmCross monodroid活动内插入Monogame视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的MvvmCross独角兽活动视图中的RelativeLayout内部构建一个Monogame视图.

I'm trying to build a Monogame view inside a RelativeLayout from my MvvmCross monodroid Activity view.

一个Android Activity继承自Microsoft.Xna.Framework.AndroidGameActivity,从而能够在RelativeLayout(运行)中运行Monogame.

An android Activity inherits from Microsoft.Xna.Framework.AndroidGameActivity to be able to run a Monogame inside a RelativeLayout (working).

我的MvvmCross活动从MvxBindingActivityView(工作)继承.

My MvvmCross Activity inherits from MvxBindingActivityView(working).

因此,我需要一种方法来运行游戏并在同一活动中绑定一些数据.

So, I need a way to run the game and bind some datas within the same activity.

预先感谢您的帮助.

推荐答案

松散地说,您可以通过继承一些接口,然后剪切并粘贴少量执行基本加载和分配的代码,将任何Activity转换为MvxActivity.的ViewModel.

Loosely speaking, you can translate any Activity to an MvxActivity by inheriting some interfaces and by then cutting and pasting a small amount of code which does the basic loading and assignation of the ViewModel.

例如请参阅添加的#RegionIMvxAndroidView<TViewModel>以使

e.g. see the #Region and IMvxAndroidView<TViewModel> added to make MvxActivityView.cs from a normal Activity.

例如这是用于将专门的Activity(例如Google的MapActivity)改编为

e.g. it's the same region and interface used for adapting a specialised Activity like Google's MapActivity into MvxMapActivityView.cs

在此级别上,活动/视图"具有ViewModel,可以在C#代码中使用,但是没有巧妙的xml膨胀-它没有巧妙的Binding支持.

At this level, the Activity/View has a ViewModel which can be used in C# code, but has no clever xml inflation - it has no clever Binding support.

可以在此级别编写代码-我交付的应用程序没有绑定-但许多用户也喜欢添加DataBinding ...

Code can be written at this level - I've shipped apps without binding - but many users prefer to add DataBinding too...

要添加此DataBinding支持,您需要添加更多代码来提供BindingInflate,绑定存储,绑定处理等.

To add this DataBinding support, you need to add a bit more code which provides BindingInflate, storage of bindings, disposal of bindings, etc.

例如使用IMvxBindingActivity界面和#region扩展原始的MvxActivityView:

e.g. a raw MvxActivityView is extended using the IMvxBindingActivity interface and a #region like: MvxBindingActivityView.cs

例如MvxMapActivityView使用相同的区域和界面扩展:

e.g. MvxMapActivityView is extended using the same region and interface: MvxBindingMapActivityView.cs

因此,您可以扩展自定义AndroidGameActivity:

So to extend your the custom AndroidGameActivity:

  1. AndroidGameActivity继承以获取ViewModelOwningGameActivity<T>,并从MvxActivityView<T>剪切并粘贴IMvxAndroidView<TViewModel>接口和#region以提供ViewModel方法,字段和属性.
  1. Inherit from AndroidGameActivity to get ViewModelOwningGameActivity<T> and cut and paste the IMvxAndroidView<TViewModel> interface and #region from MvxActivityView<T> to provide the ViewModel methods, fields and properties.

然后假设您要绑定:

  1. ViewModelOwningGameActivity<T>继承以获取BindingGameActivity<T>,并从MvxBindingActivityView<T>剪切并粘贴IMvxBindingActivity#region以获得绑定方法
  1. Inherit from ViewModelOwningGameActivity<T> to get BindingGameActivity<T> and cut and paste the IMvxBindingActivity and #region from MvxBindingActivityView<T> to get the binding methods


对于专业活动,您可能需要添加更多内容-例如您可以为MapActivity添加一些自定义帮助程序方法以绘制点和线,或者为GameActivity添加无论游戏做什么 ...,但这取决于各个实现.


For specialist Activities you may want to add more - e.g. you may could add some custom helper methods for the MapActivity to plot points and lines, or for GameActivity to do whatever games do... but this is up to individual implementations.

很抱歉,改编活动"时需要剪切和粘贴代码-我已尝试将其降至最低.但是,到目前为止,编写Mvx确实是我真正想要使用C#进行多重继承或Mixins的一遍.

Sorry about the cut and paste of code required in adapting Activities - I have tried to keep this to a minimum. However, writing Mvx is the one time so far that I've really wanted Multiple Inheritance or Mixins in C#

这篇关于在MvvmCross monodroid活动内插入Monogame视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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