MainViewModelからAccountsViewModelに移動しようとしています。アプリケーションが起動すると、MainViewModelにスタックされます。私はかなりのデバッグを行い、複数の例を調べましたが、この問題を解決することはできません。関連するクラスは下記の通りです。何か他のものが必要な場合は教えてください。MvvmCross 5.4 Android Fragments:ViewModelにナビゲートできません
のApp
using DebtBuddy.Core.ViewModels;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.IoC;
namespace DebtBuddy.Core
{
public class App : MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
CreatableTypes()
.EndingWith("Repository")
.AsInterfaces()
.RegisterAsLazySingleton();
RegisterNavigationServiceAppStart<MainViewModel>();
}
}
}
セットアップ
using Android.Content;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.Platform;
using MvvmCross.Droid.Views;
using MvvmCross.Droid.Support.V7.AppCompat;
using DebtBuddy.Core.Repositories;
using MvvmCross.Platform;
namespace DebtBuddy.Droid
{
public class Setup : MvxAppCompatSetup
{
public Setup(Context applicationContext) : base(applicationContext)
{
}
protected override IMvxApplication CreateApp()
{
var dbConn = FileAccessHelper.GetLocalFilePath("account.db3");
Mvx.RegisterSingleton(new AccountRepository(dbConn));
return new Core.App();
}
protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}
}
}
MainViewModel
using MvvmCross.Core.Navigation;
using MvvmCross.Core.ViewModels;
namespace DebtBuddy.Core.ViewModels
{
public class MainViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public MainViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
ShowAccountsViewModel = new MvxAsyncCommand(async() => await
_navigationService.Navigate<AccountsViewModel>());
}
public IMvxAsyncCommand ShowAccountsViewModel { get; private set; }
}
}
MAINVIEW
using Android.App;
using MvvmCross.Droid.Support.V7.AppCompat;
using DebtBuddy.Core.ViewModels;
using Android.OS;
using MvvmCross.Droid.Views.Attributes;
namespace DebtBuddy.Droid.Views
{
[MvxActivityPresentation]
[Activity(Theme = "@style/AppTheme")]
public class MainView : MvxAppCompatActivity<MainViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MainView);
ViewModel.ShowAccountsViewModel.ExecuteAsync();
}
}
}
MainView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
AccountsViewModel
using System.Collections.ObjectModel;
using DebtBuddy.Core.Extensions;
using DebtBuddy.Core.Interfaces.IDataServices;
using DebtBuddy.Core.Models;
using MvvmCross.Core.Navigation;
using MvvmCross.Core.ViewModels;
namespace DebtBuddy.Core.ViewModels
{
public class AccountsViewModel : MvxViewModel
{
private readonly IAccountDataService _accountDataService;
private readonly IMvxNavigationService _navigationService;
public AccountsViewModel(IMvxNavigationService navigationService, IAccountDataService accountDataService)
{
_navigationService = navigationService;
_accountDataService = accountDataService;
ShowCreateAccountViewModelCommand = new MvxAsyncCommand(async() => await _navigationService.Navigate<CreateAccountViewModel>());
ShowAccountDetailViewModelCommand = new MvxAsyncCommand<Account (item => _navigationService.Navigate<AccountDetailViewModel, Account>(item));
}
public IMvxAsyncCommand ShowCreateAccountViewModelCommand { get; private set; }
public IMvxAsyncCommand<Account> ShowAccountDetailViewModelCommand { get; private set; }
private ObservableCollection<Account> _accounts;
public ObservableCollection<Account> Accounts
{
get => _accounts;
set
{
_accounts = value;
RaisePropertyChanged(() => Accounts);
}
}
public override void Prepare()
{
LoadAccountsFromDatabase();
}
private async void LoadAccountsFromDatabase()
{
Accounts = (await _accountDataService.GetAllAccounts()).ToObservableCollection();
}
}
}
AccountsView
using Android.OS;
using MvvmCross.Droid.Views.Attributes;
using DebtBuddy.Core.ViewModels;
using MvvmCross.Droid.Support.V4;
using Android.Runtime;
using Android.Views;
using MvvmCross.Binding.Droid.BindingContext;
namespace DebtBuddy.Droid.Views
{
[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.content_frame, true)]
[Register(nameof(AccountsView))]
public class AccountsView : MvxFragment<AccountsViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.AccountsView, null);
return view;
}
}
}
AccountsView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_frame"
android:orientation="vertical"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Mvx.MvxListView
android:id="@+id/account_list"
android:divider="@null"
android:scrollbars="vertical"
android:choiceMode="singleChoice"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="left|start"
local:MvxItemTemplate="@layout/item_account"
local:MvxBind="ItemsSource Accounts; ItemClick ShowAccountDetailViewModelCommand" />
<Button
android:id="@+id/addAccountButton"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Add Account"
android:textSize="17dp"
android:textColor="@color/black"
local:MvxBind="Click ShowCreateAccountViewModelCommand" />
</LinearLayout>
間違ったビューを膨らませていないのでしょうか?あなたの 'AccountsView'フラグメントは、' CreateAccountView'というXMLビューを膨張させており、あなたが期待しているXMLレイアウトは 'AccountsView'と呼ばれています。サイドノートでは、デフォルトである 'MvxAppCompatSetup'を使用するときに' MvxAppCompatViewPresenter'プレゼンターをオーバーライドする必要はありません。 – Plac3Hold3r
あなたは正しいです。私はAccountsViewを膨らませたいと思っていました。私はそれを修正し、MvxAppCompatViewPresenterのオーバーライドを削除しました。私は起動時にまだ空白の白い画面が表示されています。私は私の変更を反映するために質問を編集しました。 – b2norma
アプリケーションの出力ウィンドウに関連するものは何ですか? – nmilcoff