本文整理汇总了C#中IDataContext.ToNonReadOnly方法的典型用法代码示例。如果您正苦于以下问题:C# IDataContext.ToNonReadOnly方法的具体用法?C# IDataContext.ToNonReadOnly怎么用?C# IDataContext.ToNonReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataContext
的用法示例。
在下文中一共展示了IDataContext.ToNonReadOnly方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModuleContext
public ModuleContext(PlatformInfo platform, LoadMode mode, IIocContainer iocContainer, IDataContext context,
IList<Assembly> assemblies)
{
_platform = platform ?? PlatformInfo.Unknown;
_mode = mode;
_iocContainer = iocContainer;
_context = context.ToNonReadOnly();
_assemblies = assemblies ?? Empty.Array<Assembly>();
}
示例2: TryShowAsync
public INavigationOperation TryShowAsync(IViewModel viewModel, IDataContext context,
IViewModelPresenter parentPresenter)
{
if (!CanShowViewModel(viewModel, context, parentPresenter))
return null;
var tcs = new TaskCompletionSource<object>();
var operation = new NavigationOperation(tcs.Task);
context = context.ToNonReadOnly();
context.AddOrUpdate(NavigationConstants.ViewModel, viewModel);
var provider = viewModel.GetIocContainer(true).Get<INavigationProvider>();
provider.CurrentNavigationTask.TryExecuteSynchronously(_ =>
{
try
{
var task = provider.NavigateAsync(operation.ToOperationCallback(), context);
tcs.TrySetFromTask(task);
}
catch (Exception e)
{
tcs.TrySetException(e);
throw;
}
});
return operation;
}
示例3: Start
public virtual void Start(IDataContext context = null)
{
Initialize();
context = context.ToNonReadOnly();
if (!context.Contains(NavigationConstants.IsDialog))
context.Add(NavigationConstants.IsDialog, false);
var app = MvvmApplication.Current;
var viewModelType = app.GetStartViewModelType();
var mappingProvider = app.IocContainer.Get<IViewMappingProvider>();
IViewMappingItem mapping = mappingProvider.FindMappingForViewModel(viewModelType, context.GetData(NavigationConstants.ViewName), true);
if (typeof(Page).IsAssignableFrom(mapping.ViewType))
{
_rootWindow = CreateNavigationWindow();
var service = CreateNavigationService(_rootWindow);
app.IocContainer.BindToConstant(service);
}
app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this);
app.Start(context);
}
示例4: GetAccessor
protected virtual ISingleBindingSourceAccessor GetAccessor(object model, string path, IDataContext context, bool isSource, Func<IDataContext, object> commandParameterDelegate = null)
{
var source = new MultiPathObserver(model, BindingPath.Create(path), false);
if (commandParameterDelegate != null)
{
context = context.ToNonReadOnly();
context.AddOrUpdate(BindingBuilderConstants.CommandParameter, commandParameterDelegate);
}
return new BindingSourceAccessor(source, context, !isSource);
}
示例5: GetViewModel
/// <summary>
/// Creates an instance of the specified view model.
/// </summary>
/// <param name="getViewModel">The specified delegate to create view model.</param>
/// <param name="dataContext">The specified <see cref="IDataContext" />.</param>
/// <returns>
/// An instance of <see cref="IViewModel" />.
/// </returns>
public IViewModel GetViewModel(GetViewModelDelegate<IViewModel> getViewModel, IDataContext dataContext)
{
Should.NotBeNull(getViewModel, "getViewModel");
Should.NotBeNull(dataContext, "dataContext");
dataContext = dataContext.ToNonReadOnly();
IIocContainer iocContainer = CreateViewModelIocContainer(dataContext);
IViewModel viewModel = getViewModel(iocContainer);
if (!viewModel.IsInitialized)
InitializeViewModel(viewModel, dataContext, iocContainer);
return viewModel;
}
示例6: RestoreViewModel
/// <summary>
/// Restores the view model from state context.
/// </summary>
/// <param name="viewModelState">The specified state <see cref="IDataContext" />.</param>
/// <param name="throwOnError">
/// <c>true</c> to throw an exception if the view model cannot be restored; <c>false</c> to return null.
/// </param>
/// <param name="dataContext">The specified <see cref="IDataContext" />.</param>
/// <returns>
/// An instance of <see cref="IViewModel" />.
/// </returns>
public IViewModel RestoreViewModel(IDataContext viewModelState, IDataContext dataContext, bool throwOnError)
{
try
{
dataContext = dataContext.ToNonReadOnly();
if (viewModelState == null)
viewModelState = DataContext.Empty;
else
dataContext.Merge(viewModelState);
IViewModel viewModel;
if (!dataContext.GetData(InitializationConstants.IgnoreRestoredViewModelCache))
{
Guid id;
if (viewModelState.TryGetData(IdViewModelConstant, out id))
{
viewModel = GetOrAddRestoredViewModel(id).GetViewModel();
if (viewModel != null)
return viewModel;
}
}
RestoredViewModel restoredParentViewModel = null;
IViewModel parentViewModel = null;
Guid idParent;
if (viewModelState.TryGetData(IdParentViewModelConstant, out idParent))
{
restoredParentViewModel = GetOrAddRestoredViewModel(idParent);
parentViewModel = restoredParentViewModel.GetViewModel();
if (parentViewModel != null)
dataContext.AddOrUpdate(InitializationConstants.ParentViewModel, parentViewModel);
}
viewModel = RestoreViewModel(viewModelState, dataContext);
if (viewModel != null)
{
if (restoredParentViewModel != null && parentViewModel == null)
restoredParentViewModel.AddChildViewModel(viewModel);
OnViewModelRestored(viewModel, viewModelState, dataContext);
Tracer.TraceViewModel(AuditAction.Restored, viewModel);
if (ReferenceEquals(viewModelState, DataContext.Empty))
Tracer.Warn("The view model '{0}' was restored without state.", viewModel);
return viewModel;
}
if (throwOnError)
throw ExceptionManager.ViewModelCannotBeRestored();
}
catch (Exception e)
{
if (throwOnError)
throw;
Tracer.Warn(e.Flatten(true));
}
return null;
}
示例7: CreateBuilder
public IBindingBuilder CreateBuilder(IDataContext context = null)
{
context = context.ToNonReadOnly();
if (!context.Contains(BindingBuilderConstants.BuildDelegate))
context.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate);
return new BindingBuilder(context);
}
示例8: RestoreViewModel
public IViewModel RestoreViewModel(IDataContext viewModelState, IDataContext dataContext, bool throwOnError)
{
try
{
dataContext = dataContext.ToNonReadOnly();
if (viewModelState == null)
viewModelState = DataContext.Empty;
else
dataContext.Merge(viewModelState);
IViewModel viewModel;
if (!dataContext.GetData(InitializationConstants.IgnoreViewModelCache))
{
Guid id;
if (viewModelState.TryGetData(ViewModelConstants.Id, out id))
{
viewModel = GetOrAddCachedViewModel(id).GetViewModel();
if (viewModel != null)
return viewModel;
}
}
CachedViewModel restoredParentViewModel = null;
IViewModel parentViewModel = null;
Guid idParent;
if (viewModelState.TryGetData(ViewModelConstants.IdParent, out idParent))
{
restoredParentViewModel = GetOrAddCachedViewModel(idParent);
parentViewModel = restoredParentViewModel.GetViewModel();
if (parentViewModel != null)
dataContext.AddOrUpdate(InitializationConstants.ParentViewModel, parentViewModel);
}
var restoring = Restoring;
if (restoring != null)
{
var args = new ViewModelRestoringEventArgs { Context = dataContext, ViewModelState = viewModelState };
restoring(this, args);
dataContext = args.Context ?? DataContext.Empty;
}
viewModel = RestoreViewModelInternal(viewModelState, dataContext);
if (viewModel != null)
{
if (restoredParentViewModel != null && parentViewModel == null)
restoredParentViewModel.AddChildViewModel(viewModel);
OnViewModelRestored(viewModel, viewModelState, dataContext);
var restored = Restored;
if (restored != null)
{
var args = new ViewModelRestoredEventArgs(viewModel)
{
Context = dataContext,
ViewModelState = viewModelState
};
restored(this, args);
}
Tracer.TraceViewModel(ViewModelLifecycleType.Restored, viewModel);
if (ReferenceEquals(viewModelState, DataContext.Empty))
Tracer.Warn("The view model '{0}' was restored without state.", viewModel);
return viewModel;
}
if (throwOnError)
throw ExceptionManager.ViewModelCannotBeRestored();
}
catch (Exception e)
{
if (throwOnError)
throw;
Tracer.Warn(e.Flatten(true));
}
return null;
}
示例9: GetViewModel
public IViewModel GetViewModel(GetViewModelDelegate<IViewModel> getViewModel, IDataContext dataContext)
{
Should.NotBeNull(getViewModel, nameof(getViewModel));
Should.NotBeNull(dataContext, nameof(dataContext));
dataContext = dataContext.ToNonReadOnly();
IViewModel viewModel = getViewModel(GetIocContainer(dataContext));
if (!viewModel.IsInitialized)
InitializeViewModel(viewModel, dataContext);
return viewModel;
}
示例10: Start
public virtual void Start(IDataContext context = null)
{
Initialize();
context = context.ToNonReadOnly();
if (!context.Contains(NavigationConstants.IsDialog))
context.Add(NavigationConstants.IsDialog, false);
var app = MvvmApplication.Current;
app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this);
app.Start(context);
}
示例11: NavigateAsync
public Task NavigateAsync(IOperationCallback callback, IDataContext context)
{
Should.NotBeNull(context, nameof(context));
IViewModel viewModel = context.GetData(NavigationConstants.ViewModel);
if (viewModel == null)
throw new InvalidOperationException($"The '{GetType()}' provider doesn't support the DataContext without navigation target.");
context = context.ToNonReadOnly();
if (ReferenceEquals(viewModel, CurrentViewModel))
{
if (callback != null)
CallbackManager.Register(OperationType.PageNavigation, viewModel, callback, context);
return Empty.Task;
}
//The view model is already shown as page and we need to bring it to front
if (viewModel.Settings.State.Contains(IsNavigatedConstant))
context.AddOrUpdate(NavigationProviderConstants.BringToFront, true);
string viewName = viewModel.GetViewName(context);
var vmType = viewModel.GetType();
var mappingItem = ViewMappingProvider.FindMappingForViewModel(vmType, viewName, true);
var id = Guid.NewGuid().ToString("n");
var parameter = GenerateNavigationParameter(vmType, id);
var tcs = new TaskCompletionSource<object>();
CurrentNavigationTask.TryExecuteSynchronously(_ =>
ThreadManager.InvokeOnUiThreadAsync(() =>
{
_navigatedTcs = tcs;
_navigationTargetVm = viewModel;
_currentCallback = callback;
_lastContext = context;
_currentOperationId = id;
if (_navigationService.Navigate(mappingItem, parameter, context))
ClearCacheIfNeed(context, viewModel);
}));
return tcs.Task;
}