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

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

问题描述

我正在尝试从我的 MvvmCross monodroid Activity 视图在相对布局中构建 Monogame 视图.

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

从 Microsoft.Xna.Framework.AndroidGameActivity 继承的 android Activity 能够在 RelativeLayout(工作)中运行 Monogame.

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

我的 MvvmCross Activity 继承自 MvxBindingActivityView(working).

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的视图模型.

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 添加到 MvxActivityView.cs 来自普通 Activity.

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

例如它与用于将 Google 的 MapActivity 等专门 Activity 适配为 MvxMapActivityView.cs

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

在这个级别,Activity/View 有一个 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.

可以在这个级别编写代码 - 我发布的应用程序没有绑定 - 但许多用户也更喜欢添加数据绑定...

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,例如:MvxBindingActivityView.cs

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

例如MvxMapActivityView 使用相同的区域和界面进行扩展:MvxBindingMapActivityView.cs

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

所以要扩展您的自定义AndroidGameActivity:

So to extend your the custom AndroidGameActivity:

  1. AndroidGameActivity继承得到ViewModelOwningGameActivity,剪切粘贴IMvxAndroidView界面和#region 来自 MvxActivityView 以提供 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继承得到BindingGameActivity并剪切粘贴IMvxBindingActivity#regionMvxBindingActivityView 获取绑定方法
  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# 中实现多重继承或 Mixin 的一次

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 Activity 中插入 Monogame 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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