refactor(ui): own retained controller lifetimes

This commit is contained in:
Erik 2026-07-10 23:35:26 +02:00
parent 921c388e2c
commit 5d9e98c118
21 changed files with 373 additions and 35 deletions

View file

@ -34,7 +34,7 @@ public sealed class RetailWindowHandle
public string Name { get; }
public UiElement OuterFrame { get; }
public UiElement ContentRoot { get; }
public IRetainedPanelController? Controller { get; }
public IRetainedPanelController? Controller { get; private set; }
public IRetainedWindowStateController? StateController { get; }
public bool IsRegistered => !_disposed;
public bool IsVisible => OuterFrame.Visible;
@ -70,6 +70,19 @@ public sealed class RetailWindowHandle
Controller?.OnShown();
}
internal void AttachController(IRetainedPanelController controller)
{
ObjectDisposedException.ThrowIf(_disposed, this);
ArgumentNullException.ThrowIfNull(controller);
if (ReferenceEquals(Controller, controller)) return;
if (Controller is not null)
throw new InvalidOperationException($"Retained window '{Name}' already owns a controller.");
Controller = controller;
if (_notifiedVisible)
Controller.OnShown();
}
internal void NotifyVisibility(bool visible)
{
if (_notifiedVisible == visible) return;