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


C# IDataContext.ToNonReadOnly方法代码示例

本文整理汇总了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>();
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:9,代码来源:ModuleContext.cs

示例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;
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:25,代码来源:DynamicViewModelNavigationPresenter.cs

示例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);
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:20,代码来源:WpfBootstrapperBase.cs

示例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);
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:10,代码来源:SingleBindingSourceAccessorTest.cs

示例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;
 }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:19,代码来源:ViewModelProvider.cs

示例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;
        }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:67,代码来源:ViewModelProvider.cs

示例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);
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:7,代码来源:BindingProvider.cs

示例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;
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:75,代码来源:ViewModelProvider.cs

示例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;
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:10,代码来源:ViewModelProvider.cs

示例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);
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:10,代码来源:WinFormsBootstrapperBase.cs

示例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;
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:37,代码来源:NavigationProvider.cs


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