本文整理汇总了C#中ViewBase.InitializeData方法的典型用法代码示例。如果您正苦于以下问题:C# ViewBase.InitializeData方法的具体用法?C# ViewBase.InitializeData怎么用?C# ViewBase.InitializeData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewBase
的用法示例。
在下文中一共展示了ViewBase.InitializeData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FetchViewModel
/// <summary>
/// This is method is called by each view in order to get it's view-model as well as place it in
/// the SceneContext if the "Save & Load" option is checked in it's inspector
/// </summary>
/// <param name="viewBase">The view that is requesting it's view-model.</param>
/// <returns>A new view model or the view-model with the identifier specified found in the scene context.</returns>
public static ViewModel FetchViewModel(ViewBase viewBase)
{
if (viewBase.ViewModelObject != null)
{
return viewBase.ViewModelObject;
}
// Attempt to resolve it by the identifier
//var contextViewModel = uFrameMVVMKernel.Container.Resolve<ViewModel>(viewBase.Identifier);
// It now only registers under the viewmodeltype to allow multip different view-models with the same identifier
var contextViewModel =
uFrameKernel.Container.Resolve(viewBase.ViewModelType, viewBase.Identifier) as ViewModel;
// If it doesn't resolve by the identifier we need to create it
if (contextViewModel == null)
{
// Either use the controller to create it or create it ourselves
contextViewModel = MVVMKernelExtensions.CreateViewModel(viewBase.ViewModelType);
contextViewModel.Identifier = viewBase.Identifier;
// Register it, this is usually when a non registered element is treated like a single-instance anways
uFrameKernel.Container.RegisterInstance(viewBase.ViewModelType, contextViewModel,
string.IsNullOrEmpty(viewBase.Identifier) ? null : viewBase.Identifier);
// Register it under the generic view-model type
//uFrameMVVMKernel.Container.RegisterInstance<ViewModel>(contextViewModel, viewBase.Identifier);
uFrameKernel.EventAggregator.Publish(new ViewModelCreatedEvent()
{
ViewModel = contextViewModel
});
}
// If we found a view-model
if (contextViewModel != null)
{
// If the view needs to be overriden it will initialize with the inspector values
if (viewBase.OverrideViewModel)
{
viewBase.InitializeData(contextViewModel);
}
return viewBase.ViewModelObject = contextViewModel;
}
return contextViewModel;
}