0

これで何が間違っていたのかわかりませんでした。チュートリアルに従いました ( https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/master/N-16-CollectABull-Part5/CollectABull.Core/ViewModels/ListViewModel .cs ) を参照して、リストをバインドし、特定のリスト アイテムが選択されたときに詳細画面を表示する方法について説明します。私の問題は、アイテムを選択しても何も起こらないことです。抽象アクティビティ/ビューモデルを利用したいので、流暢なバインディングを使用してデータバインドを処理しています。一部のコード スニペットは次のとおりです。

私のリストのレイアウト:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:local="http://schemas.android.com/apk/res/project"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <Mvx.MvxListView android:id="@+id/List"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:choiceMode="singleChoice"
               local:MvxItemTemplate="@layout/list_item"
           />
</RelativeLayout>

マイ アクティビティ:

public class List : AbstractList {

    public new ListView ViewModel{
        get { return (ListView) base.ViewModel; }
        set { base.ViewModel = value; }
    }

    protected override void OnCreate(Bundle bundle) {
        base.OnCreate(bundle);

        var set = this.CreateBindingSet<List, ListView>();
        set.Bind(list).For(x => x.ItemsSource).To(vm => vm.List);
        set.Bind(list).For(x => x.ItemClick).To(vm => vm.ShowDetail);
        set.Apply();

    }
}

私の抽象的な活動:

 public class AbstractList : MvxActivity{

    protected Legacy.LegacyBar actionBar;
    protected MvxListView list;

    protected override void OnCreate(Bundle bundle) {
        base.OnCreate(bundle);
        RequestWindowFeature(WindowFeatures.NoTitle);
        SetContentView(Resource.Layout.list);

        actionBar = FindViewById<Legacy.LegacyBar>(Resource.Id.actionbar);
        list = FindViewById<MvxListView>(Resource.Id.List);

        actionBar.SetGravity(GravityFlags.Center);
        actionBar.Title = Title;
    }
}

私のビューモデル:

public class ListView : AbstractListView<Item>{

    private readonly IRepository repository;

    public ListView(IRepository repo){
        repository= repo;
        DataBind();
    }

    public List<Item> List{
        get { return list; }
        set{
            list = value;
            RaisePropertyChanged(() => List);
        }
    }

    protected override Task<QueryResult<Item>> DataBindCall(){
        return repository.Get(new Query());
    }

    protected override void SetResultList(Item[] resultList){
        List = resultList.ToList();
    }
}

私の抽象ビューモデル:

public abstract class AbstractListView<T> : MvxViewModel where T: class, new (){

    protected List<T> list;

    public IMvxCommand ShowDetail {
        get {
            return new MvxCommand<Item>(item => ShowViewModel<ItemView>(new ItemView.Navigation() { Id = item.ID }));
        }
    }

    protected abstract Task<QueryResult<T>> DataBindCall();
    protected abstract void SetResultList(T[] resultList);

    protected void DataBind(){
       DataBindCall().ContinueWith(x => {
            SetResultList(x.Result.Results);
        });
    }        
}

コードをステップ実行すると、バインド呼び出しで ShowDetail で中断することがわかりますが、リストが読み込まれ、リストの項目の 1 つをクリックすると、何もしません。バインドが失敗したように見えますが、エラー メッセージや logcat からのメッセージはありません。また、詳細ページを手動でプルアップしようとしましたが、正しく読み込まれているため、詳細ページ自体に問題はありません。バインディング メカニズムと、導入したすべての抽象クラスを混同していませんか? それとも、私が見ることができなかったいくつかの非常に明白な間違いがありますか. 助けてくれてありがとう!

4

0 に答える 0