diff --git a/README.md b/README.md index 36eb2af..ab5389f 100644 --- a/README.md +++ b/README.md @@ -391,6 +391,11 @@ You can easily target elements of the dialogs via their names and types, such as + + + diff --git a/src/JamSoft.AvaloniaUI.Dialogs/Controls/WizardContainerGenerator.cs b/src/JamSoft.AvaloniaUI.Dialogs/Controls/WizardContainerGenerator.cs deleted file mode 100644 index 99ca8b5..0000000 --- a/src/JamSoft.AvaloniaUI.Dialogs/Controls/WizardContainerGenerator.cs +++ /dev/null @@ -1,181 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Controls.Generators; -using Avalonia.Controls.Primitives; -using Avalonia.Controls.Templates; -using Avalonia.LogicalTree; -using Avalonia.Reactive; -using Avalonia.Threading; - -namespace JamSoft.AvaloniaUI.Dialogs.Controls; - -/// -/// The Wizard container generator -/// -public class WizardContainerGenerator -{ - /// - /// Default constructor - /// - /// - public WizardContainerGenerator(Wizard owner) - { - Owner = owner; - } - - /// - /// The owner wizard control - /// - public Wizard Owner; - - /// - public Control CreateContainer(object item) - { - var step = (WizardStep)base.CreateContainer(item, 0, null); - - step.Bind(WizardStep.ProgressPlacementProperty, new OwnerBinding( - step, - Wizard.ButtonPlacementProperty)); - - if (step.HeaderTemplate == null) - { - step.Bind(HeaderedContentControl.HeaderTemplateProperty, new OwnerBinding( - step, - ItemsControl.ItemTemplateProperty!)); - } - - if (step.Header == null) - { - if (item is HeaderedContentControl headered) - { - step.Header = headered.Header; - } - else - { - if (!(step.DataContext is Control)) - { - step.Header = step.DataContext; - } - } - } - - if (!(step.Content is Control)) - { - step.Bind(ContentControl.ContentTemplateProperty, new OwnerBinding( - step, - Wizard.ContentTemplateProperty!)); - } - - return step; - } - - private class OwnerBinding : AvSingleSubscriberObservableBase - { - private readonly WizardStep _step; - private readonly StyledProperty _ownerProperty; - private IDisposable? _ownerSubscription; - private IDisposable? _propertySubscription; - - public OwnerBinding(WizardStep step, StyledProperty ownerProperty) - { - _step = step; - _ownerProperty = ownerProperty; - } - - protected override void Subscribed() - { - //_ownerSubscription = ControlLocator.Track(_step, 0, typeof(Wizard)).Subscribe(OwnerChanged); - } - - protected override void Unsubscribed() - { - _ownerSubscription?.Dispose(); - _ownerSubscription = null; - } - - private void OwnerChanged(ILogical c) - { - _propertySubscription?.Dispose(); - _propertySubscription = null; - - if (c is Wizard wizard) - { - // _propertySubscription = wizard.GetObservable(_ownerProperty) - // .Subscribe(x => PublishNext(x)); - } - } - } - - private abstract class AvSingleSubscriberObservableBase : IObservable, IDisposable - { - private Exception? _error; - private IObserver? _observer; - private bool _completed; - - public IDisposable Subscribe(IObserver observer) - { - _ = observer ?? throw new ArgumentNullException(nameof(observer)); - Dispatcher.UIThread.VerifyAccess(); - - if (_observer != null) - { - throw new InvalidOperationException("The observable can only be subscribed once."); - } - - if (_error != null) - { - observer.OnError(_error); - } - else if (_completed) - { - observer.OnCompleted(); - } - else - { - _observer = observer; - Subscribed(); - } - - return this; - } - - public virtual void Dispose() - { - Unsubscribed(); - _observer = null; - } - - protected abstract void Unsubscribed(); - - protected void PublishNext(T value) - { - _observer?.OnNext(value); - } - - protected void PublishCompleted() - { - _completed = true; - - if (_observer != null) - { - _observer.OnCompleted(); - Unsubscribed(); - _observer = null; - } - } - - protected void PublishError(Exception error) - { - _error = error; - - if (_observer != null) - { - _observer.OnError(error); - Unsubscribed(); - _observer = null; - } - } - - protected abstract void Subscribed(); - } -} \ No newline at end of file