Insert a Monogame view inside MvvmCross monodroid Activity

前端 未结 1 1224
甜味超标
甜味超标 2020-12-20 04:14

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

An android Activity inherits from Microsoft.Xna.Framework.And

相关标签:
1条回答
  • 2020-12-20 04:33

    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.

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

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

    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...


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

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

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


    So to extend your the custom AndroidGameActivity:

    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.

    Then assuming you want binding:

    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

    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.


    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#

    0 讨论(0)
提交回复
热议问题