using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; namespace StabilityMatrix.Avalonia.Controls; public class BetterComboBox : ComboBox { public static readonly DirectProperty SelectionBoxItemTemplateProperty = AvaloniaProperty.RegisterDirect( nameof(SelectionBoxItemTemplate), v => v.SelectionBoxItemTemplate, (x, v) => x.SelectionBoxItemTemplate = v ); private IDataTemplate? _selectionBoxItemTemplate; public IDataTemplate? SelectionBoxItemTemplate { get => _selectionBoxItemTemplate; set => SetAndRaise(SelectionBoxItemTemplateProperty, ref _selectionBoxItemTemplate, value); } /// protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); if (e.NameScope.Find("ContentPresenter") is { } contentPresenter) { if (SelectionBoxItemTemplate is { } template) { contentPresenter.ContentTemplate = template; } } } }