/// <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); _applicationLifecycle = TryGetService <IApplicationLifecycle>(dependencyResolver); _renderInterface = TryGetService <IPlatformRenderInterface>(dependencyResolver); var renderLoop = TryGetService <IRenderLoop>(dependencyResolver); Renderer = impl.CreateRenderer(this); impl.SetInputRoot(this); impl.Closed = HandleClosed; impl.Input = HandleInput; impl.Paint = HandlePaint; impl.Resized = HandleResized; impl.ScalingChanged = HandleScalingChanged; _keyboardNavigationHandler?.SetOwner(this); _accessKeyHandler?.SetOwner(this); styler?.ApplyStyles(this); ClientSize = impl.ClientSize; 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; } if (((IStyleHost)this).StylingParent is IResourceProvider applicationResources) { WeakSubscriptionManager.Subscribe( applicationResources, nameof(IResourceProvider.ResourcesChanged), this); } }
/// <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); _applicationLifecycle = TryGetService <IApplicationLifecycle>(dependencyResolver); _renderInterface = TryGetService <IPlatformRenderInterface>(dependencyResolver); var renderLoop = TryGetService <IRenderLoop>(dependencyResolver); var rendererFactory = TryGetService <IRendererFactory>(dependencyResolver); Renderer = rendererFactory?.CreateRenderer(this, renderLoop); PlatformImpl.SetInputRoot(this); PlatformImpl.Activated = HandleActivated; PlatformImpl.Deactivated = HandleDeactivated; PlatformImpl.Closed = HandleClosed; PlatformImpl.Input = HandleInput; PlatformImpl.Paint = Renderer != null ? (Action <Rect>)Renderer.Render : null; 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; } }
/// <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); }
public AvaloniaLocator(IAvaloniaDependencyResolver parentScope) { _parentScope = parentScope; }
public static T GetService <T>(this IAvaloniaDependencyResolver resolver) { return((T)resolver.GetService(typeof(T))); }
public ResolverDisposable(IAvaloniaDependencyResolver resolver, AvaloniaLocator mutable) { _resolver = resolver; _mutable = mutable; }
/// <summary> /// Initializes a new instance of the <see cref="PopupRoot"/> class. /// </summary> /// <param name="parent">The popup parent.</param> /// <param name="impl">The popup implementation.</param> /// <param name="dependencyResolver"> /// The dependency resolver to use. If null the default dependency resolver will be used. /// </param> public PopupRoot(TopLevel parent, IPopupImpl impl, IAvaloniaDependencyResolver dependencyResolver) : base(impl, dependencyResolver) { _parent = parent; }
/// <summary> /// Initializes a new instance of the <see cref="PopupRoot"/> class. /// </summary> /// <param name="dependencyResolver"> /// The dependency resolver to use. If null the default dependency resolver will be used. /// </param> public PopupRoot(IAvaloniaDependencyResolver dependencyResolver) : base(PlatformManager.CreatePopup(), dependencyResolver) { }
/// <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; _actualTransparencyLevel = PlatformImpl.TransparencyLevel; dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current; var styler = TryGetService <IStyler>(dependencyResolver); _accessKeyHandler = TryGetService <IAccessKeyHandler>(dependencyResolver); _inputManager = TryGetService <IInputManager>(dependencyResolver); _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver); _renderInterface = TryGetService <IPlatformRenderInterface>(dependencyResolver); _globalStyles = TryGetService <IGlobalStyles>(dependencyResolver); Renderer = impl.CreateRenderer(this); if (Renderer != null) { Renderer.SceneInvalidated += SceneInvalidated; } impl.SetInputRoot(this); impl.Closed = HandleClosed; impl.Input = HandleInput; impl.Paint = HandlePaint; impl.Resized = HandleResized; impl.ScalingChanged = HandleScalingChanged; impl.TransparencyLevelChanged = HandleTransparencyLevelChanged; _keyboardNavigationHandler?.SetOwner(this); _accessKeyHandler?.SetOwner(this); if (_globalStyles is object) { _globalStyles.GlobalStylesAdded += ((IStyleHost)this).StylesAdded; _globalStyles.GlobalStylesRemoved += ((IStyleHost)this).StylesRemoved; } styler?.ApplyStyles(this); ClientSize = impl.ClientSize; this.GetObservable(PointerOverElementProperty) .Select( x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>()) .Switch().Subscribe(cursor => PlatformImpl?.SetCursor(cursor?.PlatformCursor)); if (((IStyleHost)this).StylingParent is IResourceHost applicationResources) { WeakSubscriptionManager.Subscribe( applicationResources, nameof(IResourceHost.ResourcesChanged), this); } impl.LostFocus += PlatformImpl_LostFocus; }
/// <summary> /// Initializes a new instance of the <see cref="PopupRoot"/> class. /// </summary> /// <param name="dependencyResolver"> /// The dependency resolver to use. If null the default dependency resolver will be used. /// </param> public PopupRoot(IAvaloniaDependencyResolver dependencyResolver) : base(PlatformManager.CreatePopup(), dependencyResolver) { }
/// <summary> /// Initializes a new instance of the <see cref="PopupRoot"/> class. /// </summary> /// <param name="parent">The popup parent.</param> /// <param name="impl">The popup implementation.</param> /// <param name="dependencyResolver"> /// The dependency resolver to use. If null the default dependency resolver will be used. /// </param> public PopupRoot(TopLevel parent, IPopupImpl impl, IAvaloniaDependencyResolver dependencyResolver) : base(ValidatingPopupImpl.Wrap(impl), dependencyResolver) { _parent = parent; }
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}'.")); }