MVVMCross How does this View get linked to the ViewModel?
Asked Answered
A

4

8

I'm trying to figure out why I get an error message about not being able to find the right ViewModel when I'm running my iOS app.

The question I have is when I look at this example I don't understand where MainMenuView gets bound to MainMenuViewModel.

Can someone answer this for me?

Thanks,

PkL728

Assessor answered 11/7, 2013 at 19:48 Comment(0)
M
9

They are bound by class names: for XXXView should be corresponded XXXViewModel

Minsk answered 11/7, 2013 at 19:54 Comment(5)
So in my iOS project I have a ProductsView class which extends MvxTableViewController and in my core project I have a ProductsViewModel class. When I run my program I get this error: Failed to load ViewModel for type LoginProductsMVVM.Core.ViewModels.ProductsViewModel from locator MvxDefaultViewModelLocator... Do I have this set up wrong?Assessor
Ok... so my error was related to a method being called in my ProductsViewModel constructor that was erroring out. Not a helpful error message!! Thanks Roman!Assessor
Make sure you have trace turned on - https://mcmap.net/q/1247398/-mvvmcross-mvx-trace-usage/… - then you'll see more of the 'not helpful' error message.Thurible
OMG. Wasted 2 days due to this.Remaremain
Name convention is the default setting. There are several ways to override it: mvvmcross.com/documentation/fundamentals/…Cabrilla
G
1

Just want to add to the answer: double-check the names of the views after renaming (even Resharper renaming is not perfect). Spent several dozens of minutes (and a beer can), catching similar MvvmCross's error Could not find view for %ViewModelName%.

Gschu answered 8/7, 2014 at 20:33 Comment(0)
O
1

I'm getting this on a project that I've just upgraded to MvvmCross 4. I don't have much experience with MvvmCross, and the project hasn't been maintained for a few years, so it's possible something else is wrong.

I ended up hard coding the mappings in Setup::InitializeViewLookup because I don't have time to waste on it anymore.

Overwrite answered 12/4, 2016 at 20:0 Comment(0)
F
1

For anyone who ends up here having the same problem I had. I was getting this error in an Android project because my (properly named) view was extending Activity and not MvxActivity (happens easily when you use Xamarin Studio's "Add Android Activity" feature)

Foin answered 24/6, 2016 at 1:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.