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


C# IDataContext.TryGetData方法代码示例

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


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

示例1: Observe

        public virtual IObserver Observe(object target, IBindingPath path, bool ignoreAttachedMembers, IDataContext context)
        {
            Should.NotBeNull(target, nameof(target));
            Should.NotBeNull(path, nameof(path));
            if (path.IsEmpty)
                return new EmptyPathObserver(target, path);

            bool hasStablePath;
            bool observable;
            bool optional;
            if (context == null || !context.TryGetData(BindingBuilderConstants.HasStablePath, out hasStablePath))
                hasStablePath = BindingServiceProvider.HasStablePathDefault;
            if (context == null || !context.TryGetData(BindingBuilderConstants.Observable, out observable))
                observable = BindingServiceProvider.ObservablePathDefault;
            if (context == null || !context.TryGetData(BindingBuilderConstants.Optional, out optional))
                optional = BindingServiceProvider.OptionalBindingDefault;
            if (path.IsSingle)
                return new SinglePathObserver(target, path, ignoreAttachedMembers, hasStablePath, observable, optional);
            return new MultiPathObserver(target, path, ignoreAttachedMembers, hasStablePath, observable, optional);
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:20,代码来源:ObserverProvider.cs

示例2: CanShowViewModel

        private bool CanShowViewModel(IViewModel viewModel, IDataContext context,
            IViewModelPresenter parentPresenter)
        {
            bool data;
            if (context.TryGetData(NavigationConstants.SuppressPageNavigation, out data) && data)
                return false;

            if (_canShowViewModel == null)
                return CanShowViewModelDefault(viewModel, context, parentPresenter);
            return _canShowViewModel(viewModel, context, parentPresenter);
        }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:11,代码来源:DynamicViewModelNavigationPresenter.cs

示例3: LoadState

 public void LoadState(IDataContext state)
 {
     int data;
     if (state.TryGetData("Depth", out data))
         Depth = data;
 }
开发者ID:xRoulanDx,项目名称:MugenMvvmToolkit.Samples,代码行数:6,代码来源:BackStackViewModel.cs

示例4: Navigate

        /// <summary>
        ///     Displays the content located at the specified <see cref="IViewMappingItem" />.
        /// </summary>
        /// <param name="source">
        ///     The <c>IViewPageMappingItem</c> of the content to display.
        /// </param>
        /// <param name="parameter">
        ///     A <see cref="T:System.Object" /> that contains data to be used for processing during
        ///     navigation.
        /// </param>
        /// <param name="dataContext">
        ///     The specified <see cref="IDataContext" />.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the content was successfully displayed; otherwise, <c>false</c>.
        /// </returns>
        public bool Navigate(IViewMappingItem source, object parameter, IDataContext dataContext)
        {
            Should.NotBeNull(source, "source");
            if (_rootPage == null)
                return false;
            if (!RaiseNavigating(new NavigatingCancelEventArgs(source, NavigationMode.New, parameter)))
                return false;
            if (dataContext == null)
                dataContext = DataContext.Empty;

            var viewModel = dataContext.GetData(NavigationConstants.ViewModel);
            bool animated;
            if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
            {
                if (viewModel != null)
                    viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated);
            }
            else
                animated = UseAnimations;
            Page page;
            if (viewModel == null)
                page = (Page)ServiceProvider.IocContainer.Get(source.ViewType);
            else
                page = (Page)ViewManager.GetOrCreateView(viewModel, null, dataContext);
            page.SetNavigationParameter(parameter);
            ClearNavigationStackIfNeed(dataContext, page, _rootPage.PushAsync(page, animated));
            return true;
        }
开发者ID:windygu,项目名称:MugenMvvmToolkit,代码行数:44,代码来源:NavigationService.cs

示例5: Navigate

 public bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
 {
     Should.NotBeNull(source, nameof(source));
     if (dataContext == null)
         dataContext = DataContext.Empty;
     dataContext.TryGetData(NavigationProviderConstants.BringToFront, out _bringToFront);
     var bringToFront = _bringToFront;
     var result = Navigate(source.ViewType, parameter, dataContext.GetData(NavigationConstants.ViewModel));
     if (result)
     {
         if (bringToFront)
             dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
         ClearNavigationStackIfNeed(dataContext);
     }
     return result;
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:16,代码来源:FrameNavigationService.cs

示例6: InitializeParentViewModel

 private static void InitializeParentViewModel(IViewModel viewModel, IViewModel parentViewModel, IDataContext context)
 {
     if (parentViewModel == null)
         return;
     ObservationMode observationMode;
     if (!context.TryGetData(InitializationConstants.ObservationMode, out observationMode))
         observationMode = ApplicationSettings.ViewModelObservationMode;
     viewModel.Settings.Metadata.AddOrUpdate(ViewModelConstants.ParentViewModel, ToolkitExtensions.GetWeakReference(parentViewModel));
     if (observationMode.HasFlagEx(ObservationMode.ParentObserveChild))
         viewModel.Subscribe(parentViewModel);
     if (observationMode.HasFlagEx(ObservationMode.ChildObserveParent))
         parentViewModel.Subscribe(viewModel);
 }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:13,代码来源:ViewModelProvider.cs

示例7: ResolveObject

        /// <summary>
        ///     Gets an instance of <see cref="ISourceValue" /> by the specified name.
        /// </summary>
        /// <param name="name">The specified name.</param>
        /// <param name="context">The specified data context, if any.</param>
        /// <param name="throwOnError">
        ///     true to throw an exception if the type cannot be found; false to return null. Specifying
        ///     false also suppresses some other exception conditions, but not all of them.
        /// </param>
        /// <returns>An instance of <see cref="ISourceValue" />.</returns>
        public virtual ISourceValue ResolveObject(string name, IDataContext context, bool throwOnError)
        {
            Should.NotBeNullOrWhitespace(name, "name");
            if (context != null && BindingSourceResourceName.Equals(name, StringComparison.Ordinal))
            {
                object src;
                if (context.TryGetData(BindingBuilderConstants.Source, out src))
                    return new BindingResourceObject(src, true);

                object target = null;
                IDataBinding binding;
                if (context.TryGetData(BindingConstants.Binding, out binding))
                {
                    WeakReference srcWeak;
                    if (binding.Context.TryGetData(BindingConstants.Source, out srcWeak))
                        return new BindingResourceObject(srcWeak);
                    target = binding.TargetAccessor.Source.GetSource(false);
                }
                if (target == null)
                    target = context.GetData(BindingBuilderConstants.Target);
                if (target != null)
                    return BindingServiceProvider.ContextManager.GetBindingContext(target);
            }
            lock (_objects)
            {
                DynamicResourceObject value;
                if (!_objects.TryGetValue(name, out value))
                {
                    var targetResourceObject = GetTargetResourceObject(name, context);
                    if (targetResourceObject != null)
                        return targetResourceObject;
                    if (Tracer.TraceWarning)
                        Tracer.Warn(BindingExceptionManager.CannotResolveInstanceFormat2, "resource", name, GetType().Name);
                    value = new DynamicResourceObject();
                    _objects[name] = value;
                }
                return value;
            }
        }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:49,代码来源:BindingResourceResolver.cs

示例8: TryClose

 public virtual bool TryClose(IViewModel viewModel, IDataContext dataContext)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     if (dataContext == null)
         dataContext = DataContext.Empty;
     bool animated;
     if (!dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
         animated = UseAnimations;
     var controllers = NavigationController.ViewControllers.ToList();
     for (int i = 0; i < controllers.Count; i++)
     {
         if (controllers[i].DataContext() == viewModel)
         {
             controllers.RemoveAt(i);
             --i;
         }
     }
     if (NavigationController.ViewControllers.Length != controllers.Count)
     {
         var topViewController = NavigationController.TopViewController;
         NavigationController.SetViewControllers(controllers.ToArray(), animated);
         if (!ReferenceEquals(NavigationController.TopViewController, topViewController))
             DidPopViewController(this, EventArgs.Empty);
     }
     return true;
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:26,代码来源:NavigationService.cs

示例9: ResolveObject

        public virtual ISourceValue ResolveObject(string name, IDataContext context, bool throwOnError)
        {
            Should.NotBeNull(name, nameof(name));
            if (context != null && BindingSourceResourceName.Equals(name, StringComparison.Ordinal))
            {
                object src;
                if (context.TryGetData(BindingBuilderConstants.Source, out src))
                    return src as ISourceValue ?? new ConstResourceObject(src);

                object target = null;
                IDataBinding binding;
                if (context.TryGetData(BindingConstants.Binding, out binding))
                {
                    WeakReference srcWeak;
                    if (binding.Context.TryGetData(BindingConstants.Source, out srcWeak))
                        return new ConstResourceObject(srcWeak);
                    target = binding.TargetAccessor.Source.GetActualSource(false);
                }
                if (target == null)
                    target = context.GetData(BindingBuilderConstants.Target);
                if (target != null)
                    return BindingServiceProvider.ContextManager.GetBindingContext(target);
            }
            var targetResourceObject = GetTargetResourceObject(name, context);
            if (targetResourceObject == null)
            {
                var converter = ResolveConverter(name, context, false);
                if (converter == null)
                    return GetOrAddDynamicResource(name, true);
                return new ConstResourceObject(converter);
            }
            return targetResourceObject;
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:33,代码来源:BindingResourceResolver.cs

示例10: TryClose

 /// <summary>
 ///     Tries to close view-model page.
 /// </summary>
 public virtual bool TryClose(IViewModel viewModel, IDataContext dataContext)
 {
     Should.NotBeNull(viewModel, "viewModel");
     if (dataContext == null)
         dataContext = DataContext.Empty;
     bool animated;
     if (!dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
         animated = UseAnimations;
     var controllers = NavigationController.ViewControllers.ToList();
     for (int i = 0; i < controllers.Count; i++)
     {
         if (controllers[i].GetDataContext() == viewModel)
         {
             controllers.RemoveAt(i);
             --i;
         }
     }
     if (NavigationController.ViewControllers.Length != controllers.Count)
         NavigationController.SetViewControllers(controllers.ToArray(), animated);
     return true;
 }
开发者ID:windygu,项目名称:MugenMvvmToolkit,代码行数:24,代码来源:NavigationService.cs

示例11: Navigate

        /// <summary>
        ///     Displays the content located at the specified <see cref="IViewMappingItem" />.
        /// </summary>
        /// <param name="source">
        ///     The <c>IViewPageMappingItem</c> of the content to display.
        /// </param>
        /// <param name="parameter">
        ///     A <see cref="T:System.Object" /> that contains data to be used for processing during
        ///     navigation.
        /// </param>
        /// <param name="dataContext">
        ///     The specified <see cref="IDataContext" />.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the content was successfully displayed; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool Navigate(IViewMappingItem source, object parameter, IDataContext dataContext)
        {
            Should.NotBeNull(source, "source");
            EnsureInitialized();
            if (!RaiseNavigating(new NavigatingCancelEventArgs(source, NavigationMode.New, parameter)))
                return false;
            if (dataContext == null)
                dataContext = DataContext.Empty;

            IViewModel viewModel = dataContext.GetData(NavigationConstants.ViewModel);
            UIViewController viewController;
            if (viewModel == null)
                viewController = (UIViewController)ServiceProvider.IocContainer.Get(source.ViewType);
            else
                viewController = (UIViewController)ViewManager.GetOrCreateView(viewModel, null, dataContext);

            viewController.SetNavigationParameter(parameter);
            bool shouldNavigate = true;
            if (_window != null)
            {
                var controller = _window.RootViewController as UINavigationController;
                if (controller == null)
                {
                    shouldNavigate = false;
                    controller = new MvvmNavigationController(viewController);
                    _window.RootViewController = controller;
                }
                InitializeNavigationController(controller);
            }
            if (shouldNavigate)
            {
                bool animated;
                if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
                {
                    if (viewModel != null)
                        viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated);
                }
                else
                    animated = UseAnimations;
                if (!ClearNavigationStackIfNeed(viewController, dataContext, animated))
                    NavigationController.PushViewController(viewController, animated);
            }
            var view = viewController as IViewControllerView;
            if (view == null || view.Mediator.IsAppeared)
                RaiseNavigated(viewController, NavigationMode.New, parameter);
            else
                view.Mediator.ViewDidAppearHandler += OnViewDidAppearHandlerNew;
            return true;
        }
开发者ID:windygu,项目名称:MugenMvvmToolkit,代码行数:65,代码来源:NavigationService.cs

示例12: 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

示例13: TryShowAsync

 public virtual INavigationOperation TryShowAsync(IViewModel viewModel, IDataContext context,
     IViewModelPresenter parentPresenter)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     if (ReferenceEquals(viewModel, _multiViewModel))
         return null;
     bool data;
     if (context.TryGetData(NavigationConstants.SuppressTabNavigation, out data) && data)
         return null;
     if (!CanShowViewModel(viewModel, context, parentPresenter))
         return null;
     if (MultiViewModel.ItemsSource.Contains(viewModel))
         MultiViewModel.SelectedItem = viewModel;
     else
         MultiViewModel.AddViewModel(viewModel, true);
     var operation = new NavigationOperation();
     CallbackManager.Register(OperationType.TabNavigation, viewModel, operation.ToOperationCallback(), context);
     return operation;
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:19,代码来源:DynamicMultiViewModelPresenter.cs

示例14: Navigate

        public virtual bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
        {
            Should.NotBeNull(source, nameof(source));
            if (_rootPage == null)
                return false;
            if (dataContext == null)
                dataContext = DataContext.Empty;
            dataContext.TryGetData(NavigationProviderConstants.BringToFront, out _bringToFront);
            if (!RaiseNavigating(new NavigatingCancelEventArgs(source, _bringToFront ? NavigationMode.Refresh : NavigationMode.New, parameter, true, false)))
                return false;

            var viewModel = dataContext.GetData(NavigationConstants.ViewModel);
            bool animated;
            if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
            {
                if (viewModel != null)
                    viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated);
            }
            else
                animated = UseAnimations;
            Page page = null;
            if (_bringToFront && viewModel != null)
            {
                var navigation = _rootPage.Navigation;
                if (navigation != null)
                {
                    for (int i = 0; i < navigation.NavigationStack.Count; i++)
                    {
                        var p = navigation.NavigationStack[i];
                        if (p.BindingContext == viewModel)
                        {
                            page = p;
                            navigation.RemovePage(p);
                            dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
                            break;
                        }
                    }
                }
            }
            if (page == null)
            {
                if (viewModel == null)
                    page = (Page)ServiceProvider.Get<IViewManager>().GetViewAsync(source, dataContext).Result;
                else
                    page = (Page)ViewManager.GetOrCreateView(viewModel, null, dataContext);
            }
            page.SetNavigationParameter(parameter);
            ClearNavigationStackIfNeed(dataContext, page, _rootPage.PushAsync(page, animated));
            return true;
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:50,代码来源:NavigationService.cs

示例15: TryCreateWindowViewMediator

        private IWindowViewMediator TryCreateWindowViewMediator(IViewModel viewModel, IDataContext context)
        {
            bool data;
            if (context.TryGetData(NavigationConstants.SuppressWindowNavigation, out data) && data)
                return null;

            var viewName = viewModel.GetViewName(context);
            IViewMappingItem mappingItem = ViewMappingProvider.FindMappingForViewModel(viewModel.GetType(), viewName, false);
            if (mappingItem == null)
                return null;

            IWindowViewMediator viewMediator;
            if (!viewModel.Settings.Metadata.TryGetData(WindowViewMediatorConstant, out viewMediator))
            {
                viewMediator = CreateWindowViewMediator(viewModel, mappingItem.ViewType, context);
                if (viewMediator != null)
                    viewModel.Settings.Metadata.Add(WindowViewMediatorConstant, viewMediator);
            }
            return viewMediator;
        }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:20,代码来源:DynamicViewModelWindowPresenter.cs


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