// Cascader.cs
using System.Collections;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Melskin.Utilities;
namespace Melskin.Controls;
///
/// 用于实现级联选择器功能的控件类。该控件允许用户从多层级的数据源中选择一个值,通常应用于需要按类别或层级进行选择的场景。
///
[TemplatePart(Name = "PART_Popup", Type = typeof(Popup))]
public class Cascader : Control
{
private static readonly DependencyPropertyKey FilteredItemsSourcePropertyKey = DependencyProperty.RegisterReadOnly("FilteredItemsSource", typeof(IEnumerable), typeof(Cascader), new PropertyMetadata(null));
///
/// 用于获取经过筛选后的项集合。此属性为只读,其值由控件内部逻辑根据当前搜索条件自动更新。
///
public static readonly DependencyProperty FilteredItemsSourceProperty = FilteredItemsSourcePropertyKey.DependencyProperty;
///
/// 控制是否启用搜索功能的开关
///
public static readonly DependencyProperty IsSearchableProperty =
DependencyProperty.Register(nameof(IsSearchable), typeof(bool), typeof(Cascader), new PropertyMetadata(true));
///
/// 定义一个依赖属性,用于接收来自 XAML 的 ListBox 样式
///
public static readonly DependencyProperty PanelStyleProperty =
DependencyProperty.Register(nameof(PanelStyle), typeof(Style), typeof(Cascader), new PropertyMetadata(null));
///
/// 用于存储或获取搜索框中的文本,支持双向数据绑定。
///
public static readonly DependencyProperty SearchTextProperty = DependencyProperty.Register(nameof(SearchText), typeof(string), typeof(Cascader), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSearchTextChanged));
private readonly List