MvvmCross Xamarin 错误无法在 IOS 中找到 ViewModel 的视图



我将 Mvvmcross 从 5.7 更新到 6.x.导航工作,但当我引入 BaseViewModel 时它不起作用。 这是我的起始页视图模型的示例

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();
}
}

登录视图模型的示例

public class LoginViewModel : BaseValidationViewModel
{

public LoginViewModel(IMvxLogProvider logProvider,
IUserSettings userSettings,
IAuthenticationManager authenticationManager,
IEventLogger eventLogger,
IMvxNavigationService navigationService)
: base(userSettings, eventLogger, authenticationManager, navigationService)
{
_navigationService = navigationService;
}
}

我想使用BaseViewModel导航到LoginViewModel,但我的视图模型看不到视图,即LoginView。

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();
}
}

基本视图模型

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();
}
}

登录视图的示例

`[Register("LoginView")]
[MvxViewFor(typeof(LoginViewModel))]

 
public partial class LoginView : MvxViewController<LoginViewModel>
    
{
}`

我遇到了同样的问题,并通过在初始化视图查找中将视图映射到视图模型来解决它

protected override IMvxViewsContainer InitializeViewLookup(IDictionary<Type, Type> viewModelViewLookup)
{
viewModelViewLookup.Add(typeof(UserDatabaseUpgradeViewModel),typeof(UserDatabaseUpgradeView));
}

希望这也能解决您的问题。我正在使用 MvvmCross 6.4.x

最新更新