単純なバインディングで複数の ViewModel を使用する可能性はありますか? アイデアは、アクティビティごとに 1 つの ViewModel を持つことです。
よろしくお願いします
ニルス
https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20SimpleDialogBinding/SimpleBinding/SimpleDroidに基づいて 2 つの異なる ViewModel でテストしようとしましたが、問題があるようです。
私の構造は次のようになります。
Activity1 Activity2
| |
| |
| |
ViewModel1 ViewModel2
どちらのアクティビティも MvxSimpleBindingActivity を継承しています。
プログラムを実行すると、MvxBaseSetup から System.ArgumentException がスローされます。それが重要な部分です:
protected IDictionary<Type, Type> GetViewModelViewLookup(Assembly assembly, Type expectedInterfaceType)
{
var views = from type in assembly.GetTypes()
where !type.IsAbstract
&& expectedInterfaceType.IsAssignableFrom(type)
&& !type.Name.StartsWith("Base")
let viewModelPropertyInfo = type.GetProperty("ViewModel")
where viewModelPropertyInfo != null
let viewModelType = viewModelPropertyInfo.PropertyType
select new { type, viewModelType };
return views.ToDictionary(x => x.viewModelType, x => x.type);
}
これら 2 つの異なる ViewModel に問題がある理由がよくわかりません。