예제 #1
0
        public object GetService(Type t)
        {
            object a = 1;

            if (a != null)
            {
                a = null;
            }

            var           s = a.ToString();
            Func <object> rv;

            return(_registry.TryGetValue(t, out rv) ? rv() : _parentScope?.GetService(t));
        }
예제 #2
0
        /// <summary>
        /// Tries to get a service from an <see cref="IAvaloniaDependencyResolver"/>, logging a
        /// warning if not found.
        /// </summary>
        /// <typeparam name="T">The service type.</typeparam>
        /// <param name="resolver">The resolver.</param>
        /// <returns>The service.</returns>
        private T TryGetService <T>(IAvaloniaDependencyResolver resolver) where T : class
        {
            var result = resolver.GetService <T>();

            if (result == null)
            {
                Logger.Warning(
                    LogArea.Control,
                    this,
                    "Could not create {Service} : maybe Application.RegisterServices() wasn't called?",
                    typeof(T));
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver)
        {
            if (impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            PlatformImpl = impl;

            dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current;
            var styler = TryGetService <IStyler>(dependencyResolver);

            _accessKeyHandler          = TryGetService <IAccessKeyHandler>(dependencyResolver);
            _inputManager              = TryGetService <IInputManager>(dependencyResolver);
            _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver);
            _renderQueueManager        = TryGetService <IRenderQueueManager>(dependencyResolver);
            _applicationLifecycle      = TryGetService <IApplicationLifecycle>(dependencyResolver);

            (dependencyResolver.GetService <ITopLevelRenderer>() ?? new DefaultTopLevelRenderer()).Attach(this);

            PlatformImpl.SetInputRoot(this);
            PlatformImpl.Activated       = HandleActivated;
            PlatformImpl.Deactivated     = HandleDeactivated;
            PlatformImpl.Closed          = HandleClosed;
            PlatformImpl.Input           = HandleInput;
            PlatformImpl.Resized         = HandleResized;
            PlatformImpl.ScalingChanged  = HandleScalingChanged;
            PlatformImpl.PositionChanged = HandlePositionChanged;

            _keyboardNavigationHandler?.SetOwner(this);
            _accessKeyHandler?.SetOwner(this);
            styler?.ApplyStyles(this);

            ClientSize = PlatformImpl.ClientSize;
            this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl.ClientSize = x);
            this.GetObservable(PointerOverElementProperty)
            .Select(
                x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>())
            .Switch().Subscribe(cursor => PlatformImpl.SetCursor(cursor?.PlatformCursor));

            if (_applicationLifecycle != null)
            {
                _applicationLifecycle.OnExit += OnApplicationExiting;
            }
        }
예제 #4
0
        public object GetService(Type t)
        {
            Func <object> rv;

            return(_registry.TryGetValue(t, out rv) ? rv() : _parentScope?.GetService(t));
        }
예제 #5
0
 public static T GetService <T>(this IAvaloniaDependencyResolver resolver)
 {
     return((T)resolver.GetService(typeof(T)));
 }
예제 #6
0
 public object?GetService(Type t)
 {
     return(_registry.TryGetValue(t, out var rv) ? rv() : _parentScope?.GetService(t));
 }
 public static T GetRequiredService <T>(this IAvaloniaDependencyResolver resolver)
 {
     return((T?)resolver.GetService(typeof(T)) ?? throw new InvalidOperationException($"Unable to locate '{typeof(T)}'."));
 }
 public static object GetRequiredService(this IAvaloniaDependencyResolver resolver, Type t)
 {
     return(resolver.GetService(t) ?? throw new InvalidOperationException($"Unable to locate '{t}'."));
 }