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


C# ViewModel.GetParentViewModel方法代码示例

本文整理汇总了C#中ViewModel.GetParentViewModel方法的典型用法代码示例。如果您正苦于以下问题:C# ViewModel.GetParentViewModel方法的具体用法?C# ViewModel.GetParentViewModel怎么用?C# ViewModel.GetParentViewModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ViewModel的用法示例。


在下文中一共展示了ViewModel.GetParentViewModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProviderShouldRestoreIocContainerParentViewModelRestoreChildDuringRestoration

        public void ProviderShouldRestoreIocContainerParentViewModelRestoreChildDuringRestoration()
        {
            var parentIoc = new IocContainerMock
            {
                GetFunc = (type, s, arg3) =>
                {
                    type.ShouldEqual(typeof(ViewModel));
                    return new ViewModel();
                }
            };

            var parentViewModel = new ViewModel { IocContainer = new IocContainerMock() };
            var provider = GetViewModelProvider(new IocContainerMock { GetFunc = parentIoc.GetFunc });
            var context = new DataContext
            {
                {InitializationConstants.ParentViewModel, parentViewModel}
            };
            var restoreContext = new DataContext
            {
                {InitializationConstants.IgnoreViewModelCache, true}
            };

            var vm = new ViewModel();
            provider.InitializeViewModel(vm, context);

            var parentState = provider.PreserveViewModel(parentViewModel, DataContext.Empty);
            var state = provider.PreserveViewModel(vm, DataContext.Empty);

            ViewModel.InitializeViewModelStatic = dataContext =>
            {
                ViewModel.InitializeViewModelStatic = null;
                vm = (ViewModel)provider.RestoreViewModel(state, restoreContext, true);
            };
            parentViewModel = (ViewModel)provider.RestoreViewModel(parentState, restoreContext, true);
            parentViewModel.IocContainer = parentIoc;

            vm.GetParentViewModel().ShouldEqual(parentViewModel);
            vm.Parent.ShouldEqual(parentViewModel);
            parentViewModel.IocContainer.ShouldEqual(parentIoc);
            vm.IocContainer.ShouldEqual(parentIoc);
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:41,代码来源:ViewModelProviderTest.cs

示例2: ProviderShouldRestoreIocContainerParentViewModelAfterChildViewModelRestore

        public void ProviderShouldRestoreIocContainerParentViewModelAfterChildViewModelRestore()
        {
            var childIoc = new IocContainerMock();
            var parentIoc = new IocContainerMock
            {
                GetFunc = (type, s, arg3) =>
                {
                    type.ShouldEqual(typeof(ViewModel));
                    return new ViewModel();
                },
                CreateChild = mock => childIoc
            };
            childIoc.GetFunc = parentIoc.GetFunc;

            var parentViewModel = new ViewModel { IocContainer = new IocContainerMock() };
            var provider = GetViewModelProvider(new IocContainerMock { CreateChild = mock => parentIoc });
            var context = new DataContext
            {
                {InitializationConstants.IocContainerCreationMode, IocContainerCreationMode.ParentViewModel},
                {InitializationConstants.ParentViewModel, parentViewModel}
            };

            var vm = new ViewModel();
            provider.InitializeViewModel(vm, context);

            var parentState = provider.PreserveViewModel(parentViewModel, DataContext.Empty);
            var state = provider.PreserveViewModel(vm, DataContext.Empty);

            vm = (ViewModel)provider.RestoreViewModel(state, DataContext.Empty, true);
            parentViewModel = (ViewModel)provider.RestoreViewModel(parentState, DataContext.Empty, true);

            vm.GetParentViewModel().ShouldEqual(parentViewModel);
            parentViewModel.IocContainer.ShouldEqual(parentIoc);
            vm.IocContainer.ShouldNotEqual(childIoc);

            childIoc.GetFunc = (type, s, arg3) => childIoc;
            vm.IocContainer.Get(typeof(object)).ShouldEqual(childIoc);
        }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:38,代码来源:ViewModelProviderTest.cs


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