[英]MvvmCross Xamarin error cannot find view for ViewModel in IOS
I updated Mvvmcross from 5.7 to 6.x.我将 Mvvmcross 从 5.7 更新到 6.x。 Navigation is working but its not working when I introduce BaseViewModel.导航正在工作,但在我引入 BaseViewModel 时它不起作用。 This is the sample of my StartPageViewModel这是我的 StartPageViewModel 的示例
public class StartPageViewModel : MvxViewModel
{
protected readonly IUserSettings _userSettings;
private readonly IMvxNavigationService _navigationService;
public StartPageViewModel(IUserSettings userSettings,
IMvxNavigationService navigationService)
{
_userSettings = userSettings;
_navigationService = navigationService;
}
public IUserSettings UserSettings
{
get
{
return _userSettings;
}
}
]private IMvxCommand _loginCommand;
public IMvxCommand LoginCommand
{
get
{
return _loginCommand ?? (_loginCommand = new MvxCommand(() =>
_navigationService.Navigate<LoginViewModel>()));
}
}
public void NavigateToDashboardIfAlreadyLoggedIn()
{
}
public override void Start()
{
base.Start();
NavigateToDashboardIfAlreadyLoggedIn();
}
}
A sample of LoginViewModel LoginViewModel 示例
public class LoginViewModel : BaseValidationViewModel
{
public LoginViewModel(IMvxLogProvider logProvider,
IUserSettings userSettings,
IAuthenticationManager authenticationManager,
IEventLogger eventLogger,
IMvxNavigationService navigationService)
: base(userSettings, eventLogger, authenticationManager, navigationService)
{
_navigationService = navigationService;
}
}
I want to navigate to LoginViewModel using BaseViewModel but my viewmodel cannot see the view ie LoginView.我想使用 BaseViewModel 导航到 LoginViewModel,但我的视图模型无法看到视图,即 LoginView。
a sample of BaseValidationViewModel BaseValidationViewModel 示例
public abstract class BaseValidationViewModel : BaseViewModel
{
protected BaseValidationViewModel(IUserSettings userSettings,
IEventLogger eventLogger,
IAuthenticationManager authenticationManager,
IMvxNavigationService navigationService)
: base(userSettings, eventLogger, authenticationManager, navigationService)
{
//Some Code
}
//Some Code
public override void Start()
{
base.Start();
}
}
BaseViewModel基础视图模型
public abstract class BaseViewModel : MvxViewModel
{
protected readonly IUserSettings _userSettings;
protected readonly IEventLogger _eventLogger;
protected readonly IAuthenticationManager _authenticationManager;
private readonly IMvxNavigationService _navigationService;
protected BaseViewModel(IUserSettings userSettings,
IEventLogger eventLogger,
IAuthenticationManager authenticationManager,
IMvxNavigationService navigationService)
{
_userSettings = userSettings;
_eventLogger = eventLogger;
_authenticationManager = authenticationManager;
_navigationService = navigationService;
}
public override void Start()
{
base.Start();
}
}
a sample of LoginView登录视图示例
`[Register("LoginView")]
[MvxViewFor(typeof(LoginViewModel))]
public partial class LoginView : MvxViewController<LoginViewModel>
{
}`
I had the same problem and solved it by mapping view to viewmodel like this in the InitializeViewLookup我遇到了同样的问题,并通过在 InitializeViewLookup 中将视图映射到视图模型来解决它
protected override IMvxViewsContainer InitializeViewLookup(IDictionary<Type, Type> viewModelViewLookup)
{
viewModelViewLookup.Add(typeof(UserDatabaseUpgradeViewModel),typeof(UserDatabaseUpgradeView));
}
Hope this will solve also your problem.希望这也能解决您的问题。 I'm using MvvmCross 6.4.x我正在使用 MvvmCross 6.4.x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.