Note that there are some explanatory texts on larger screens.

plurals
  1. POMvvmCross - Failed to resolve type for ViewModel
    primarykey
    data
    text
    <p>This is related to <a href="https://stackoverflow.com/questions/17407576/mvvmcross-for-monodroid-how-to-bind-to-menu-item-click-event">another question I posted</a> but probably warrants its own. </p> <p>I need to be able to execute a Command in my ViewModel from its related Android View and specifically when an Action Bar menu item is clicked. Therefore, first of all I need access to the instance of the ViewModel. </p> <p>Firstly I tried the following line of code in the <code>OnCreateOptionsMenu(IMenu menu)</code> method of the <strong>View</strong>:</p> <pre><code>NewJobViewModel newJobViewModel = Mvx.Resolve&lt;NewJobViewModel&gt;(); </code></pre> <p>However, this caused the error: <code>"UNHANDLED EXCEPTION: Cirrious.CrossCore.Exceptions.MvxException: Failed to resolve type MyProject.Core.ViewModels.NewJobViewModel"</code></p> <p>I then tried this instead:</p> <pre><code>[Activity] public class NewJobView : MvxActivity { private NewJobViewModel _newJobViewModel; public NewJobViewModel NewJobViewModel { get { return _newJobViewModel; } set { _newJobViewModel = value; } } protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.NewJobView); this.NewJobViewModel = Mvx.Resolve&lt;NewJobViewModel&gt;(); } } </code></pre> <p>...which didn't help. </p> <p>However, adding the following to <code>Apps.cs</code> cured the error but caused other issues as it clearly hadn't given me the same instance of the ViewModel that the MvvmCross framework must have already initialised in the background(?):</p> <pre><code>public override void Initialize() { CreatableTypes() .EndingWith("NewJobViewModel") .AsTypes() .RegisterAsSingleton(); } </code></pre> <p>I clearly misunderstand some of the architecture and what's happening in the background (so I apologise if this is a basic question) but can someone please tell me what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload