如果你只是想改變命名方案,覆蓋功能CreateViewToViewModelNaming
public class Setup : MvxAndroidSetup
{
public Setup(Context applicationContext) : base(applicationContext)
{
}
protected override IMvxNameMapping CreateViewToViewModelNaming()
{
return new ReverseViewModelNaming();
}
protected override IMvxApplication CreateApp()
{
return new Core.App();
}
protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}
}
class ReverseViewModelNaming : IMvxNameMapping
{
public string Map(string inputName)
{
// MyView is presented by the view model named weiVyM (how useful :P)
return string.Join("", inputName.Reverse());
}
}
如果你想改變映射,覆蓋功能InitializeViewLookup
。如果您只是想添加一些額外的映射,請致電base.InitializeViewLookup()
。
public class Setup : MvxAndroidSetup
{
public Setup(Context applicationContext) : base(applicationContext)
{
}
protected override void InitializeViewLookup()
{
var registry = new Dictionary<Type, Type>()
{
{ typeof(FirstViewModel), typeof(FirstActivity) },
{ typeof(HomeViewModel), typeof(HomeActivity) } ,
{ typeof(DetailViewModel), typeof(DetailActivity) },
{ typeof(UploadViewModel), typeof(UploadActivity) }
};
var container = Cirrious.CrossCore.Mvx.Resolve<IMvxViewsContainer>();
container.AddAll(registry);
}
protected override IMvxApplication CreateApp()
{
return new Core.App();
}
protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}
}
謝謝Sven,我的問題是我想將同一視圖模型映射到多個視圖。這打破了字典鍵的唯一性。對於Xamarin iOS有無論如何通過另一種機制來做到這一點? – rideintothesun
這是可能的,但比你需要另一種方法。但要找到正確的方法,你必須告訴更多關於你的要求。基於什麼條件,您是否想要在瀏覽ViewModelAB時決定查看ViewA或ViewB? –
我有一個場景,我有一個摘要視圖,當點擊它時,我想顯示詳細的視圖。我想這兩個使用相同的視圖模型,爲摘要視圖的數據僅僅是細節的子集,查看數據 – rideintothesun