本文整理汇总了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);
}
示例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);
}