mirror of
https://gitee.com/chinware/atomui.git
synced 2024-11-29 18:38:16 +08:00
Combo 完成
Combo 完成
This commit is contained in:
parent
39a4917bd0
commit
accc810c5e
@ -14,12 +14,218 @@
|
||||
<showcase:ShowCaseItem
|
||||
Title="Basic"
|
||||
Description="Basic button spinner.">
|
||||
<atom:ComboBox PlaceholderText="Select" Width="400">
|
||||
<atom:ComboBoxItem>aaa</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>bbb</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>ccc</atom:ComboBoxItem>
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
</showcase:ShowCaseItem>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
<showcase:ShowCaseItem
|
||||
Title="Three sizes of Input"
|
||||
Description="There are three sizes of an ComboBox: large (40px), default (32px) and small (24px).">
|
||||
<StackPanel Orientation="Vertical" Spacing="10" Margin="0, 0, 20, 0">
|
||||
<atom:ComboBox SizeType="Large" PlaceholderText="Please select">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
<atom:ComboBox SizeType="Middle" PlaceholderText="Please select">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
<atom:ComboBox SizeType="Small" PlaceholderText="Please select">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
</StackPanel>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
<showcase:ShowCaseItem
|
||||
Title="Variants"
|
||||
Description="Variants of Input.">
|
||||
<StackPanel Orientation="Vertical" Spacing="10">
|
||||
<atom:ComboBox StyleVariant="Outline" PlaceholderText="Please select" Width="300">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox StyleVariant="Filled" PlaceholderText="Please select" Width="300">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox StyleVariant="Borderless" PlaceholderText="Please select" Width="300">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
</StackPanel>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
<showcase:ShowCaseItem
|
||||
Title="Pre / Post tab"
|
||||
Description="Using pre and post tabs example.">
|
||||
<StackPanel Orientation="Vertical" Spacing="10">
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
LeftAddOn="http://"
|
||||
RightAddOn=".com">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
RightAddOn="{atom:IconProvider Kind=SettingOutlined}"
|
||||
>
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
LeftAddOn="http://"
|
||||
InnerRightContent=".com"
|
||||
>
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
|
||||
<showcase:ShowCaseItem
|
||||
Title="prefix and suffix"
|
||||
Description="Add a prefix or suffix icons inside input.">
|
||||
<StackPanel Orientation="Vertical" Spacing="10">
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
InnerLeftContent="{atom:IconProvider Kind=UserOutlined, NormalFilledColor=#D7D7D7}"
|
||||
InnerRightContent="{atom:IconProvider Kind=InfoCircleOutlined, NormalFilledColor=#8C8C8C}"
|
||||
>
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
InnerLeftContent="¥"
|
||||
InnerRightContent="RMB">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
InnerLeftContent="¥"
|
||||
InnerRightContent="RMB" IsEnabled="False">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
<showcase:ShowCaseItem
|
||||
Title="Status"
|
||||
Description="Add status to Input with status, which could be error or warning.">
|
||||
<StackPanel Orientation="Vertical" Spacing="10" Margin="0, 0, 20, 0">
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Error">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Warning">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Error"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Warning"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Error"
|
||||
StyleVariant="Filled"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Warning"
|
||||
StyleVariant="Filled"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Error"
|
||||
StyleVariant="Borderless"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
<atom:ComboBox PlaceholderText="Please select" Width="300"
|
||||
Status="Warning"
|
||||
StyleVariant="Borderless"
|
||||
InnerLeftContent="{atom:IconProvider Kind=ClockCircleOutlined}">
|
||||
<atom:ComboBoxItem>床前明月光</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>疑是地上霜</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>举头望明月</atom:ComboBoxItem>
|
||||
<atom:ComboBoxItem>低头思故乡</atom:ComboBoxItem>
|
||||
</atom:ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
</showcase:ShowCaseItem>
|
||||
|
||||
</showcase:ShowCasePanel>
|
||||
</UserControl>
|
@ -277,16 +277,6 @@ public class AddOnDecoratedBox : ContentControl
|
||||
bottomLeft: bottomLeftRadius,
|
||||
bottomRight: bottomRightRadius);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return base.MeasureOverride(new Size(availableSize.Width - BorderThickness.Left - BorderThickness.Right, availableSize.Height));
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
return base.ArrangeOverride(new Size(finalSize.Width - BorderThickness.Left - BorderThickness.Right, finalSize.Height));
|
||||
}
|
||||
|
||||
protected virtual void UpdatePseudoClasses()
|
||||
{
|
||||
|
@ -10,6 +10,9 @@ using AvaloniaComboBox = Avalonia.Controls.ComboBox;
|
||||
|
||||
public class ComboBox : AvaloniaComboBox
|
||||
{
|
||||
public const string ErrorPC = ":error";
|
||||
public const string WarningPC = ":warning";
|
||||
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<object?> LeftAddOnProperty =
|
||||
@ -93,6 +96,7 @@ public class ComboBox : AvaloniaComboBox
|
||||
}
|
||||
|
||||
private IconButton? _openIndicatorButton;
|
||||
private ComboBoxSpinnerInnerBox? _spinnerInnerBox;
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
@ -111,12 +115,16 @@ public class ComboBox : AvaloniaComboBox
|
||||
base.OnApplyTemplate(e);
|
||||
_popup = e.NameScope.Find<Popup>(ComboBoxTheme.PopupPart);
|
||||
_openIndicatorButton = e.NameScope.Find<IconButton>(ComboBoxTheme.OpenIndicatorButtonPart);
|
||||
_spinnerInnerBox = e.NameScope.Find<ComboBoxSpinnerInnerBox>(ComboBoxTheme.SpinnerInnerBoxPart);
|
||||
|
||||
if (_openIndicatorButton is not null) {
|
||||
_openIndicatorButton.Click += (sender, args) =>
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||
};
|
||||
}
|
||||
|
||||
UpdatePseudoClasses();
|
||||
}
|
||||
|
||||
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||
@ -126,4 +134,19 @@ public class ComboBox : AvaloniaComboBox
|
||||
BindUtils.RelayBind(this, SizeTypeProperty, comboBoxItem, ComboBoxItem.SizeTypeProperty);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == StatusProperty) {
|
||||
UpdatePseudoClasses();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePseudoClasses()
|
||||
{
|
||||
PseudoClasses.Set(ErrorPC, Status == AddOnDecoratedStatus.Error);
|
||||
PseudoClasses.Set(WarningPC, Status == AddOnDecoratedStatus.Warning);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ internal class ComboBoxItemTheme : BaseControlTheme
|
||||
|
||||
public ComboBoxItemTheme() : base(typeof(ComboBoxItem)) {}
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<ComboBoxItem>((listBoxItem, scope) =>
|
||||
{
|
||||
@ -41,18 +41,22 @@ internal class ComboBoxItemTheme : BaseControlTheme
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
BuildCommonStyle();
|
||||
BuildSizeTypeStyle();
|
||||
BuildDisabledStyle();
|
||||
}
|
||||
|
||||
private void BuildCommonStyle()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
commonStyle.Add(ComboBoxItem.FontSizeProperty, GlobalTokenResourceKey.FontSize);
|
||||
commonStyle.Add(ComboBoxItem.MarginProperty, ComboBoxTokenResourceKey.ItemMargin);
|
||||
|
||||
{
|
||||
var contentPresenterStyle = new Style(selector => selector.Nesting().Template().Name(ContentPresenterPart));
|
||||
contentPresenterStyle.Add(ContentPresenter.ForegroundProperty, ComboBoxTokenResourceKey.ItemColor);
|
||||
contentPresenterStyle.Add(ContentPresenter.BackgroundProperty, ComboBoxTokenResourceKey.ItemBgColor);
|
||||
contentPresenterStyle.Add(ContentPresenter.MinHeightProperty, GlobalTokenResourceKey.ControlHeight);
|
||||
contentPresenterStyle.Add(ContentPresenter.PaddingProperty, ComboBoxTokenResourceKey.ItemPadding);
|
||||
contentPresenterStyle.Add(ContentPresenter.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadiusSM);
|
||||
commonStyle.Add(contentPresenterStyle);
|
||||
}
|
||||
|
||||
@ -76,41 +80,6 @@ internal class ComboBoxItemTheme : BaseControlTheme
|
||||
Add(commonStyle);
|
||||
}
|
||||
|
||||
private void BuildSizeTypeStyle()
|
||||
{
|
||||
var largeStyle = new Style(selector => selector.Nesting().PropertyEquals(ComboBoxItem.SizeTypeProperty, SizeType.Large));
|
||||
{
|
||||
var contentPresenterStyle = new Style(selector => selector.Nesting().Template().Name(ContentPresenterPart));
|
||||
contentPresenterStyle.Add(ContentPresenter.MinHeightProperty, GlobalTokenResourceKey.ControlHeightLG);
|
||||
contentPresenterStyle.Add(ContentPresenter.PaddingProperty, ComboBoxTokenResourceKey.ItemPaddingLG);
|
||||
contentPresenterStyle.Add(ContentPresenter.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadius);
|
||||
largeStyle.Add(contentPresenterStyle);
|
||||
}
|
||||
|
||||
Add(largeStyle);
|
||||
|
||||
var middleStyle = new Style(selector => selector.Nesting().PropertyEquals(ComboBoxItem.SizeTypeProperty, SizeType.Middle));
|
||||
{
|
||||
var contentPresenterStyle = new Style(selector => selector.Nesting().Template().Name(ContentPresenterPart));
|
||||
contentPresenterStyle.Add(ContentPresenter.MinHeightProperty, GlobalTokenResourceKey.ControlHeight);
|
||||
contentPresenterStyle.Add(ContentPresenter.PaddingProperty, ComboBoxTokenResourceKey.ItemPadding);
|
||||
contentPresenterStyle.Add(ContentPresenter.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadiusSM);
|
||||
middleStyle.Add(contentPresenterStyle);
|
||||
}
|
||||
|
||||
Add(middleStyle);
|
||||
|
||||
var smallStyle = new Style(selector => selector.Nesting().PropertyEquals(ComboBoxItem.SizeTypeProperty, SizeType.Small));
|
||||
{
|
||||
var contentPresenterStyle = new Style(selector => selector.Nesting().Template().Name(ContentPresenterPart));
|
||||
contentPresenterStyle.Add(ContentPresenter.MinHeightProperty, GlobalTokenResourceKey.ControlHeightSM);
|
||||
contentPresenterStyle.Add(ContentPresenter.PaddingProperty, ComboBoxTokenResourceKey.ItemPaddingSM);
|
||||
contentPresenterStyle.Add(ContentPresenter.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadiusXS);
|
||||
smallStyle.Add(contentPresenterStyle);
|
||||
}
|
||||
Add(smallStyle);
|
||||
}
|
||||
|
||||
private void BuildDisabledStyle()
|
||||
{
|
||||
var disabledStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Disabled));
|
||||
|
@ -24,9 +24,9 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
public const string PopupPart = "PART_Popup";
|
||||
public const string PlaceholderTextPart = "PART_PlaceholderText";
|
||||
public const string SelectedContentPresenterPart = "PART_SelectedContentPresenter";
|
||||
|
||||
public ComboBoxTheme() : base(typeof(ComboBox)) {}
|
||||
|
||||
|
||||
public ComboBoxTheme() : base(typeof(ComboBox)) { }
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<ComboBox>((comboBox, scope) =>
|
||||
@ -37,14 +37,14 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
decoratedBox.Content = innerBox;
|
||||
innerBox.RegisterInNameScope(scope);
|
||||
var popup = BuildPopup(comboBox, scope);
|
||||
|
||||
|
||||
panel.Children.Add(decoratedBox);
|
||||
panel.Children.Add(popup);
|
||||
|
||||
|
||||
return panel;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected virtual AddOnDecoratedBox BuildSpinnerDecoratedBox(ComboBox comboBox, INameScope scope)
|
||||
{
|
||||
var decoratedBox = new AddOnDecoratedBox
|
||||
@ -61,40 +61,46 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
decoratedBox.RegisterInNameScope(scope);
|
||||
return decoratedBox;
|
||||
}
|
||||
|
||||
protected virtual ComboBoxSpinnerInnerBox BuildSpinnerContent(ComboBox comboBox, INameScope scope)
|
||||
|
||||
protected virtual ComboBoxSpinnerInnerBox BuildSpinnerContent(ComboBox comboBox, INameScope scope)
|
||||
{
|
||||
var spinnerInnerBox = new ComboBoxSpinnerInnerBox()
|
||||
{
|
||||
Name = SpinnerInnerBoxPart,
|
||||
Focusable = true,
|
||||
};
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.LeftAddOnContentProperty, ComboBox.InnerLeftContentProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.RightAddOnContentProperty, ComboBox.InnerRightContentProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.StyleVariantProperty, ComboBox.StyleVariantProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.LeftAddOnContentProperty,
|
||||
ComboBox.InnerLeftContentProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.RightAddOnContentProperty,
|
||||
ComboBox.InnerRightContentProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.StyleVariantProperty,
|
||||
ComboBox.StyleVariantProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.StatusProperty, ComboBox.StatusProperty);
|
||||
CreateTemplateParentBinding(spinnerInnerBox, ComboBoxSpinnerInnerBox.SizeTypeProperty, ComboBox.SizeTypeProperty);
|
||||
|
||||
spinnerInnerBox.RegisterInNameScope(scope);
|
||||
var content = BuildComboBoxContent(comboBox, scope);
|
||||
spinnerInnerBox.Content = content;
|
||||
|
||||
|
||||
var spinnerHandleDecorator = new Border()
|
||||
{
|
||||
Name = SpinnerHandleDecoratorPart,
|
||||
BackgroundSizing = BackgroundSizing.InnerBorderEdge,
|
||||
ClipToBounds = true
|
||||
};
|
||||
|
||||
|
||||
spinnerHandleDecorator.RegisterInNameScope(scope);
|
||||
|
||||
var decreaseButtonIcon = new PathIcon()
|
||||
{
|
||||
Kind = "DownOutlined"
|
||||
};
|
||||
|
||||
TokenResourceBinder.CreateGlobalTokenBinding(decreaseButtonIcon, PathIcon.ActiveFilledBrushProperty, ButtonSpinnerTokenResourceKey.HandleHoverColor);
|
||||
TokenResourceBinder.CreateGlobalTokenBinding(decreaseButtonIcon, PathIcon.SelectedFilledBrushProperty, GlobalTokenResourceKey.ColorPrimaryActive);
|
||||
|
||||
|
||||
TokenResourceBinder.CreateGlobalTokenBinding(decreaseButtonIcon, PathIcon.ActiveFilledBrushProperty,
|
||||
ButtonSpinnerTokenResourceKey.HandleHoverColor);
|
||||
TokenResourceBinder.CreateGlobalTokenBinding(decreaseButtonIcon, PathIcon.SelectedFilledBrushProperty,
|
||||
GlobalTokenResourceKey.ColorPrimaryActive);
|
||||
|
||||
var openButton = new IconButton()
|
||||
{
|
||||
Name = OpenIndicatorButtonPart,
|
||||
@ -103,16 +109,19 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
BackgroundSizing = BackgroundSizing.InnerBorderEdge
|
||||
};
|
||||
|
||||
|
||||
openButton.RegisterInNameScope(scope);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.WidthProperty, ComboBoxTokenResourceKey.OpenIndicatorWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.IconWidthProperty, GlobalTokenResourceKey.IconSizeSM);
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.IconHeightProperty, GlobalTokenResourceKey.IconSizeSM);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.WidthProperty,
|
||||
ComboBoxTokenResourceKey.OpenIndicatorWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.IconWidthProperty,
|
||||
GlobalTokenResourceKey.IconSizeSM);
|
||||
TokenResourceBinder.CreateTokenBinding(openButton, IconButton.IconHeightProperty,
|
||||
GlobalTokenResourceKey.IconSizeSM);
|
||||
|
||||
spinnerHandleDecorator.Child = openButton;
|
||||
spinnerInnerBox.SpinnerContent = spinnerHandleDecorator;
|
||||
|
||||
|
||||
return spinnerInnerBox;
|
||||
}
|
||||
|
||||
@ -127,8 +136,8 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
Opacity = 0.3
|
||||
};
|
||||
|
||||
CreateTemplateParentBinding(placeholder, TextBlock.IsVisibleProperty, ComboBox.SelectedItemProperty,
|
||||
|
||||
CreateTemplateParentBinding(placeholder, TextBlock.IsVisibleProperty, ComboBox.SelectedItemProperty,
|
||||
BindingMode.Default,
|
||||
ObjectConverters.IsNull);
|
||||
CreateTemplateParentBinding(placeholder, TextBlock.TextProperty, ComboBox.PlaceholderTextProperty);
|
||||
@ -140,12 +149,14 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
};
|
||||
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentProperty, ComboBox.SelectionBoxItemProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentTemplateProperty, ComboBox.ItemTemplateProperty);
|
||||
|
||||
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentProperty,
|
||||
ComboBox.SelectionBoxItemProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentTemplateProperty,
|
||||
ComboBox.ItemTemplateProperty);
|
||||
|
||||
contentLayout.Children.Add(contentPresenter);
|
||||
|
||||
|
||||
return contentLayout;
|
||||
}
|
||||
|
||||
@ -159,13 +170,16 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
Placement = PlacementMode.BottomEdgeAlignedLeft,
|
||||
};
|
||||
popup.RegisterInNameScope(scope);
|
||||
|
||||
|
||||
var border = new Border();
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty, GlobalTokenResourceKey.ColorBgContainer);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty, ComboBoxTokenResourceKey.PopupBorderRadius);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.PaddingProperty, ComboBoxTokenResourceKey.PopupContentPadding);
|
||||
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty,
|
||||
GlobalTokenResourceKey.ColorBgContainer);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty,
|
||||
ComboBoxTokenResourceKey.PopupBorderRadius);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.PaddingProperty,
|
||||
ComboBoxTokenResourceKey.PopupContentPadding);
|
||||
|
||||
var scrollViewer = new MenuScrollViewer();
|
||||
var itemsPresenter = new ItemsPresenter
|
||||
{
|
||||
@ -175,14 +189,16 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
Grid.SetIsSharedSizeScope(itemsPresenter, true);
|
||||
scrollViewer.Content = itemsPresenter;
|
||||
border.Child = scrollViewer;
|
||||
|
||||
|
||||
popup.Child = border;
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty, ComboBoxTokenResourceKey.PopupMarginToAnchor);
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty, ComboBoxTokenResourceKey.PopupBoxShadows);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty,
|
||||
ComboBoxTokenResourceKey.PopupMarginToAnchor);
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty,
|
||||
ComboBoxTokenResourceKey.PopupBoxShadows);
|
||||
CreateTemplateParentBinding(popup, Popup.MaxHeightProperty, ComboBox.MaxDropDownHeightProperty);
|
||||
CreateTemplateParentBinding(popup, Popup.IsOpenProperty, ComboBox.IsDropDownOpenProperty, BindingMode.TwoWay);
|
||||
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
@ -191,7 +207,6 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
var largeStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(AddOnDecoratedBox.SizeTypeProperty, SizeType.Large));
|
||||
largeStyle.Add(AddOnDecoratedBox.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadiusLG);
|
||||
largeStyle.Add(TextElement.FontSizeProperty, GlobalTokenResourceKey.FontSizeLG);
|
||||
{
|
||||
var spinnerInnerBox = new Style(selector => selector.Nesting().Template().Name(SpinnerInnerBoxPart));
|
||||
@ -203,7 +218,6 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
var middleStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(AddOnDecoratedBox.SizeTypeProperty, SizeType.Middle));
|
||||
middleStyle.Add(AddOnDecoratedBox.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadius);
|
||||
middleStyle.Add(TextElement.FontSizeProperty, GlobalTokenResourceKey.FontSize);
|
||||
{
|
||||
var spinnerInnerBox = new Style(selector => selector.Nesting().Template().Name(SpinnerInnerBoxPart));
|
||||
spinnerInnerBox.Add(ComboBoxSpinnerInnerBox.FontSizeProperty, GlobalTokenResourceKey.FontSize);
|
||||
@ -214,14 +228,63 @@ internal class ComboBoxTheme : BaseControlTheme
|
||||
var smallStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(AddOnDecoratedBox.SizeTypeProperty, SizeType.Small));
|
||||
smallStyle.Add(AddOnDecoratedBox.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadiusSM);
|
||||
smallStyle.Add(TextElement.FontSizeProperty, GlobalTokenResourceKey.FontSizeSM);
|
||||
{
|
||||
var spinnerInnerBox = new Style(selector => selector.Nesting().Template().Name(SpinnerInnerBoxPart));
|
||||
spinnerInnerBox.Add(ComboBoxSpinnerInnerBox.FontSizeProperty, GlobalTokenResourceKey.FontSizeSM);
|
||||
smallStyle.Add(spinnerInnerBox);
|
||||
}
|
||||
commonStyle.Add(smallStyle);
|
||||
|
||||
BuildStatusStyle();
|
||||
Add(commonStyle);
|
||||
}
|
||||
|
||||
private void BuildStatusStyle()
|
||||
{
|
||||
var borderlessStyle =
|
||||
new Style(selector => selector.Nesting()
|
||||
.PropertyEquals(AddOnDecoratedBox.StyleVariantProperty,
|
||||
AddOnDecoratedVariant.Borderless));
|
||||
|
||||
{
|
||||
var errorStyle = new Style(selector => selector.Nesting().Class(AddOnDecoratedBox.ErrorPC));
|
||||
var contentPresenter = new Style(selector => selector.Nesting().Template().Name(SelectedContentPresenterPart));
|
||||
contentPresenter.Add(ContentPresenter.ForegroundProperty, GlobalTokenResourceKey.ColorErrorText);
|
||||
errorStyle.Add(contentPresenter);
|
||||
borderlessStyle.Add(errorStyle);
|
||||
}
|
||||
|
||||
{
|
||||
var warningStyle = new Style(selector => selector.Nesting().Class(AddOnDecoratedBox.WarningPC));
|
||||
var contentPresenter = new Style(selector => selector.Nesting().Template().Name(SelectedContentPresenterPart));
|
||||
contentPresenter.Add(ContentPresenter.ForegroundProperty, GlobalTokenResourceKey.ColorWarningText);
|
||||
warningStyle.Add(contentPresenter);
|
||||
borderlessStyle.Add(warningStyle);
|
||||
}
|
||||
|
||||
Add(borderlessStyle);
|
||||
|
||||
var filledStyle =
|
||||
new Style(selector => selector.Nesting()
|
||||
.PropertyEquals(AddOnDecoratedBox.StyleVariantProperty,
|
||||
AddOnDecoratedVariant.Filled));
|
||||
|
||||
{
|
||||
var errorStyle = new Style(selector => selector.Nesting().Class(AddOnDecoratedBox.ErrorPC));
|
||||
|
||||
var contentPresenter = new Style(selector => selector.Nesting().Template().Name(SelectedContentPresenterPart));
|
||||
contentPresenter.Add(ContentPresenter.ForegroundProperty, GlobalTokenResourceKey.ColorErrorText);
|
||||
errorStyle.Add(contentPresenter);
|
||||
filledStyle.Add(errorStyle);
|
||||
}
|
||||
|
||||
{
|
||||
var warningStyle = new Style(selector => selector.Nesting().Class(AddOnDecoratedBox.WarningPC));
|
||||
var contentPresenter = new Style(selector => selector.Nesting().Template().Name(SelectedContentPresenterPart));
|
||||
contentPresenter.Add(ContentPresenter.ForegroundProperty, GlobalTokenResourceKey.ColorWarningText);
|
||||
warningStyle.Add(contentPresenter);
|
||||
filledStyle.Add(warningStyle);
|
||||
}
|
||||
|
||||
Add(filledStyle);
|
||||
}
|
||||
}
|
@ -69,20 +69,10 @@ internal class ComboBoxToken : ButtonSpinnerToken
|
||||
/// </summary>
|
||||
public Color ItemSelectedBgColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表项小号内间距
|
||||
/// </summary>
|
||||
public Thickness ItemPaddingSM { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表项内间距
|
||||
/// </summary>
|
||||
public Thickness ItemPadding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表项大号内间距
|
||||
/// </summary>
|
||||
public Thickness ItemPaddingLG { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表项外边距
|
||||
@ -118,9 +108,7 @@ internal class ComboBoxToken : ButtonSpinnerToken
|
||||
ItemSelectedBgColor = _globalToken.ControlItemBgActive;
|
||||
|
||||
ItemDisabledColor = colorTextDisabled;
|
||||
|
||||
ItemPaddingLG = new Thickness(_globalToken.Padding);
|
||||
ItemPaddingSM = new Thickness(_globalToken.PaddingXS, _globalToken.PaddingXS);
|
||||
|
||||
ItemPadding = new Thickness(_globalToken.PaddingSM, _globalToken.PaddingXS);
|
||||
ItemMargin = new Thickness(0, 0.5);
|
||||
}
|
||||
|
@ -159,9 +159,7 @@ namespace AtomUI.Theme.Styling
|
||||
public static readonly TokenResourceKey ItemBgColor = new TokenResourceKey("ComboBox.ItemBgColor", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemHoverBgColor = new TokenResourceKey("ComboBox.ItemHoverBgColor", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemSelectedBgColor = new TokenResourceKey("ComboBox.ItemSelectedBgColor", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemPaddingSM = new TokenResourceKey("ComboBox.ItemPaddingSM", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemPadding = new TokenResourceKey("ComboBox.ItemPadding", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemPaddingLG = new TokenResourceKey("ComboBox.ItemPaddingLG", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey ItemMargin = new TokenResourceKey("ComboBox.ItemMargin", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey PopupMarginToAnchor = new TokenResourceKey("ComboBox.PopupMarginToAnchor", "AtomUI.Token");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user