0
我有Xamarin.Forms應用程序。目前我正在Android上測試我的應用程序,現在我遇到了未顯示下一個視圖(頁面)的問題。我開始調試它,當我導航到我的頁面,然後實例構造函數正在調用它自己,並且在此構造函數的主體中時,我停止了其中我有另一個具有靜態字段和靜態方法的類的另一個初始化。當這個靜態構造函數正在初始化我的字段,然後它跳過實例構造函數,並且因爲它,我認爲它沒有完成初始化所有的事情,而是在沒有實際導航的情況下完成操作。 這裏是一切的起點:靜態構造函數以某種方式阻止實例構造函數
private void OnCreateNewUserButtonTapped()
{
_navigationService.NavigateAsync($"{nameof(NavigationBarPage)}/{nameof(LoginingPage)}");
}
然後在這裏:
public LoginingPageViewModel(INavigationService navigationService, IKeyboardHelper keyboardHelper, ISecuredDataProvider securedDataProvider)
{
_navigationService = navigationService;
_keyboardHelper = keyboardHelper;
_checkBox = new ShowPasswordCheckBoxModel();
_entries = new LogInPageEntriesModel();
_accountManager = new AccountManager(new ClientAuthorization(), securedDataProvider);
Func<bool> isLogInCommandEnable =() =>
StringService.CheckForNullOrEmpty(_entries.LoginText, _entries.PasswordText);
CheckedCommand = new DelegateCommand(OnCheckBoxTapped);
LogInCommand = new DelegateCommand(OnLogInTapped, isLogInCommandEnable);
//_keyboardHelper.ShowKeyboard();
}
這裏是的AccountManager類的地方工作不正確:
private readonly ClientAuthorization _clientAuthorization;
private readonly ISecuredDataProvider _securedDataProvider;
private static string _lastUser = GetLastUserFromStorage();
private readonly List<string> _users;
public AccountManager(ClientAuthorization clientAuthorization, ISecuredDataProvider securedDataProvider)
{
_clientAuthorization = clientAuthorization;
_securedDataProvider = securedDataProvider;
_users = _securedDataProvider.RetreiveAll(ConstantsService.ProviderName).Select(acc => acc.Username) as List<string>;
}
...
public static string GetLastUserFromStorage()
{
if (Application.Current.Properties.ContainsKey("_lastUser"))
return Application.Current.Properties[_lastUser] as string;
return string.Empty;
}
如果推出它沒有初始化 「_lastUser」那麼它的工作完美。
它的工作原理!謝謝。 –