using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.LogicalTree; using FluentAvalonia.UI.Controls; using Nito.Disposables.Internals; using StabilityMatrix.Avalonia.ViewModels.Inference; using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Extensions; #pragma warning disable CS0657 // Not a valid attribute location for this declaration namespace StabilityMatrix.Avalonia.Controls; [PseudoClasses(":editEnabled")] [Transient] public class StackEditableCard : TemplatedControl { private ListBox? listBoxPart; // ReSharper disable once MemberCanBePrivate.Global public static readonly StyledProperty IsListBoxEditEnabledProperty = AvaloniaProperty.Register("IsListBoxEditEnabled"); public bool IsListBoxEditEnabled { get => GetValue(IsListBoxEditEnabledProperty); set => SetValue(IsListBoxEditEnabledProperty, value); } /// protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); listBoxPart = e.NameScope.Find("PART_ListBox"); if (listBoxPart != null) { // Register handlers to attach container behavior // Forward container index changes to view model ((IChildIndexProvider)listBoxPart).ChildIndexChanged += (_, args) => { if (args.Child is Control { DataContext: StackExpanderViewModel vm }) { vm.OnContainerIndexChanged(args.Index); } }; /*listBoxPart .GetPropertyChangedObservable(DraggableListBox.IsDraggingEnabledProperty) .Subscribe(args => { IsListBoxEditEnabled = (bool)args.NewValue!; });*/ } var addButton = e.NameScope.Find