Fix Selection isEnabled bug

This commit is contained in:
chinboy
2025-12-27 21:35:17 +08:00
parent 658c3ab2b7
commit be8a0cf217
5 changed files with 41 additions and 29 deletions
@@ -13,7 +13,7 @@
<WrapPanel ItemSpacing="10" LineSpacing="10">
<atom:Select Mode="Single" PlaceholderText="Please select" Width="120"
DefaultValues="lucy">
<atom:SelectOption Header="Jack" Value="jack" />
<atom:SelectOption Header="Jack" Value="jack" IsEnabled="False" />
<atom:SelectOption Header="Lucy" Value="lucy" />
<atom:SelectOption Header="yiminghe" Value="Yiminghe" />
<atom:SelectOption Header="Disabled" IsEnabled="False" Value="disabled" />
+5 -1
View File
@@ -799,7 +799,11 @@ public class Select : TemplatedControl,
{
if (Mode == SelectMode.Single)
{
SetCurrentValue(IsDropDownOpenProperty, false);
var optionItem = source.FindAncestorOfType<SelectOptionItem>();
if (optionItem != null && optionItem.IsEnabled)
{
SetCurrentValue(IsDropDownOpenProperty, false);
}
}
e.Handled = true;
}
@@ -294,8 +294,12 @@ internal class SelectOptions : List
{
for (var i = 0; i < ItemCount; i++)
{
var item = ListDefaultView.Items[i];
var container = ListDefaultView.ContainerFromIndex(i);
container?.SetCurrentValue(IsEnabledProperty, true);
if (item is ISelectOption selectOption)
{
container?.SetCurrentValue(IsEnabledProperty, selectOption.IsEnabled);
}
}
}
}
@@ -9,31 +9,28 @@
<themes:ListItemTheme TargetType="atom:SelectOptionItem" />
</ControlTheme.BasedOn>
<Style Selector="^:is(atom|SelectOptionItem)">
<Setter Property="FontSize" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionFontSize}}"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Cursor" Value="Hand"/>
<Style Selector="^[DisabledItemHoverEffect=False]:pointerover">
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionActiveBg}}" />
</Style>
<Style Selector="^[IsActive=True]">
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionActiveBg}}" />
</Style>
<Style Selector="^[IsSelected=True]">
<Setter Property="FontWeight" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedFontWeight}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedColor}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedBg}}"/>
</Style>
<Style Selector="^[SizeType=Middle]">
<Setter Property="Padding" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionPadding}}" />
<Setter Property="MinHeight" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionHeight}}" />
</Style>
<Setter Property="FontSize" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionFontSize}}"/>
<Setter Property="Focusable" Value="False"/>
<Style Selector="^[DisabledItemHoverEffect=False]:pointerover">
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionActiveBg}}" />
</Style>
<Style Selector="^[IsActive=True]">
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionActiveBg}}" />
</Style>
<Style Selector="^[IsSelected=True]">
<Setter Property="FontWeight" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedFontWeight}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedColor}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionSelectedBg}}"/>
</Style>
<Style Selector="^[SizeType=Middle]">
<Setter Property="Padding" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionPadding}}" />
<Setter Property="MinHeight" Value="{DynamicResource {x:Static atom:SelectTokenKey.OptionHeight}}" />
</Style>
</ControlTheme>
</ResourceDictionary>
@@ -151,7 +151,10 @@
<Setter Property="IsShowSelectedIndicator" Value="False" />
</Style>
<Style Selector="^[IsSearchEnabled=False]">
<Setter Property="Cursor" Value="Hand"/>
<Style Selector="^ /template/ atom|SelectAddOnDecoratedBox#PART_AddOnDecoratedBox">
<Setter Property="Cursor" Value="Hand"/>
</Style>
<Style Selector="^ /template/ ContentPresenter#SingleSelectResultPresenter">
<Setter Property="IsVisible" Value="True" />
</Style>
@@ -177,7 +180,9 @@
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^[IsSearchEnabled=False]">
<Setter Property="Cursor" Value="Hand"/>
<Style Selector="^ /template/ atom|SelectAddOnDecoratedBox#PART_AddOnDecoratedBox">
<Setter Property="Cursor" Value="Hand"/>
</Style>
</Style>
<Style Selector="^ /template/ atom|SelectOptions#PART_OptionsBox">
<Setter Property="IsShowSelectedIndicator" Value="True" />
@@ -190,7 +195,9 @@
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^[IsSearchEnabled=False]">
<Setter Property="Cursor" Value="Hand"/>
<Style Selector="^ /template/ atom|SelectAddOnDecoratedBox#PART_AddOnDecoratedBox">
<Setter Property="Cursor" Value="Hand"/>
</Style>
</Style>
<Style Selector="^ /template/ atom|SelectOptions#PART_OptionsBox">
<Setter Property="IsShowSelectedIndicator" Value="True" />