From 1661026cdcc2fd0dcb420a4de4f81e7bf3947c1d Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 11 Sep 2024 01:32:11 +0800 Subject: [PATCH] feat: introduce IsSelectable for TreeComboBox. --- demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml | 5 +++++ demo/Ursa.Demo/ViewModels/TreeComboBoxDemoViewModel.cs | 7 +++++-- src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml | 1 + src/Ursa/Controls/ComboBox/TreeComboBox.cs | 2 +- src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs | 9 +++++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml b/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml index e204bff..e46b9d1 100644 --- a/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml +++ b/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml @@ -52,6 +52,11 @@ PopupInnerTopContent="Top" PopupInnerBottomContent="Bottom" ItemsSource="{Binding Items}"> + + + diff --git a/demo/Ursa.Demo/ViewModels/TreeComboBoxDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/TreeComboBoxDemoViewModel.cs index 998bb41..bca68e5 100644 --- a/demo/Ursa.Demo/ViewModels/TreeComboBoxDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/TreeComboBoxDemoViewModel.cs @@ -19,7 +19,8 @@ public partial class TreeComboBoxDemoViewModel: ObservableObject { new TreeComboBoxItemViewModel() { - ItemName = "Item 1-1", + ItemName = "Item 1-1 (Not selectable)", + IsSelectable = false, Children = new List() { new TreeComboBoxItemViewModel() @@ -45,7 +46,8 @@ public partial class TreeComboBoxDemoViewModel: ObservableObject { new TreeComboBoxItemViewModel() { - ItemName = "Item 2-1" + ItemName = "Item 2-1 (Not selectable)", + IsSelectable = false, }, new TreeComboBoxItemViewModel() { @@ -64,5 +66,6 @@ public partial class TreeComboBoxDemoViewModel: ObservableObject public partial class TreeComboBoxItemViewModel : ObservableObject { [ObservableProperty] private string? _itemName; + [ObservableProperty] private bool _isSelectable = true; public List Children { get; set; } = new (); } \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml b/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml index db9b61b..d3f5f71 100644 --- a/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml +++ b/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml @@ -217,6 +217,7 @@ + diff --git a/src/Ursa/Controls/ComboBox/TreeComboBox.cs b/src/Ursa/Controls/ComboBox/TreeComboBox.cs index e88d55e..a039893 100644 --- a/src/Ursa/Controls/ComboBox/TreeComboBox.cs +++ b/src/Ursa/Controls/ComboBox/TreeComboBox.cs @@ -198,7 +198,7 @@ public class TreeComboBox: ItemsControl, IClearControl, IInnerContentControl, IP if (_popup is not null && _popup.IsOpen && _popup.IsInsidePopup(source)) { var container = GetContainerFromEventSource(source); - if (container is null) return; + if (container is null || !container.IsSelectable) return; var item = TreeItemFromContainer(container); if (item is null) return; if (SelectedItem is not null) diff --git a/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs b/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs index fae2526..6da7949 100644 --- a/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs +++ b/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs @@ -33,6 +33,15 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable set => SetValue(IsExpandedProperty, value); } + public static readonly StyledProperty IsSelectableProperty = AvaloniaProperty.Register( + nameof(IsSelectable), true); + + public bool IsSelectable + { + get => GetValue(IsSelectableProperty); + set => SetValue(IsSelectableProperty, value); + } + public static readonly DirectProperty LevelProperty = AvaloniaProperty.RegisterDirect(