当前位置: 首页>>代码示例>>C#>>正文


C# ViewBase.InitializeData方法代码示例

本文整理汇总了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;
        }
开发者ID:xclouder,项目名称:godbattle,代码行数:51,代码来源:ViewService.cs


注:本文中的ViewBase.InitializeData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。