title: MvvmCross overriding viewmodel associations for Android
body: <p>I am trying to override the default view model association but having no luck so far.  I need to override this default behavior because some of my ViewModels do not follow the name convention assumed by the default view model lookup.  For example, I have some ViewModels in namespace Pidac.Core.ViewModels, while the Views are defined in MyApplication.Droid.Views.</p>
  
  <p>I have tried the option to provide an explicity type mapping in Setup.cs of the Droid project as follows:</p>
  
  <pre><code> protected override void InitializeViewLookup()
          {
              var viewModelViewLookup = new Dictionary&lt;Type, Type&gt;()
              {
                    { typeof (FirstViewModel), typeof(FirstView) },     
                    { typeof (FloatSettingViewModel), typeof(FloatSettingView) },
                    { typeof (SettingsViewModel), typeof(SettingsView) },
                    { typeof (SearchResultDialogViewModel), typeof(SearchResultDialogView) },
              };
  
              var container = Mvx.Resolve&lt;IMvxViewsContainer&gt;();
              container.AddAll(viewModelViewLookup);      
          }
  </code></pre>
  
  <p>With this, my application no longer goes past the MvvmCross logo screen.</p>
  
  <p>Alternately, I tried providing the concrete view model type within FloatSettingView.cs as follows:</p>
  
  <pre><code>[Activity(Label = "settings", Theme = "@android:style/Theme.NoTitleBar")]
      public class FloatSettingView : MvxActivity
      {
          protected override void OnCreate(Bundle bundle)
          {
              base.OnCreate(bundle);
              SetContentView(Resource.Layout.FloatSettingView);
          }
  
          public new FloatSettingViewModel ViewModel
          {
              get { return base.ViewModel as FloatSettingViewModel; }
              set { base.ViewModel = value; }
          }
      }
  </code></pre>
  
  <p>Using only this second approach, without providing a view model to view type mapping in Setup.cs, I get an exception when the framework attempts to load FloatSettingView.  Exception is  <code>Failed to find viewmodel for Pidac.Core.ViewModels.FloatSettingViewModel.</code></p>
  
  <p>I tried the third option of decorating my view with the MvxViewForAttribute as follows:</p>
  
  <pre><code> [Activity(Label = "settings", Theme = "@android:style/Theme.NoTitleBar")]
  [MvxViewFor(typeof(FloatSettingViewModel))]
          public class FloatSettingView : MvxActivity
          {
              protected override void OnCreate(Bundle bundle)
              {
                  base.OnCreate(bundle);
                  SetContentView(Resource.Layout.FloatSettingView);
              } 
  
          }
  </code></pre>
  
  <p>with no luck.  I am obviously overlooking something here. Before I dig into the source, has anyone done this before?</p>
  
  <p>TIA.</p>