using System.Windows; using System.Windows.Controls; using System.Windows.Data; namespace ytLive.Helpers; /// Gives a ComboBox's CLOSED box a different template from its drop-down /// rows (TASK 63). /// /// WPF asks an with the ContentPresenter's /// templated parent: the itself when it renders the closed /// selection box, the when it renders a row. That is the /// only way to tell the two apart — ComboBox.SelectionBoxItemTemplate is /// read-only, and WPF copies ItemTemplate into it, so a ComboBox otherwise /// cannot show one thing when shut and another when open. /// /// Verified against WPF on .NET 8 (2026-10-21): with the rows' presenter the /// templated parent is the ComboBoxItem, with the closed box's it is the ComboBox. /// public sealed class ClosedBoxTemplateSelector : DataTemplateSelector { /// The template for the closed box — what the creator reads while the /// drop-down is shut. public DataTemplate? ClosedTemplate { get; set; } /// The template for the drop-down rows. public DataTemplate? RowTemplate { get; set; } public override DataTemplate? SelectTemplate(object item, DependencyObject container) => container is FrameworkElement { TemplatedParent: ComboBox } ? ClosedTemplate : RowTemplate; }