feat: enhance ComboBox controls.

This commit is contained in:
Zhang Dian
2025-01-14 00:44:04 +08:00
parent 9bbcb1bd33
commit 061645c5cd
3 changed files with 53 additions and 27 deletions

View File

@@ -50,4 +50,7 @@
<StreamGeometry x:Key="SemiIconStar">
M10.75 1.9c.4-1.2 2.1-1.2 2.5 0l1.99 6.12h6.45a1.3 1.3 0 0 1 .77 2.37l-5.22 3.78 2 6.11c.39 1.2-1 2.2-2.02 1.46L12 17.96l-5.22 3.78c-1.02.75-2.4-.25-2.01-1.46l1.99-6.11-5.22-3.78a1.3 1.3 0 0 1 .77-2.37h6.45l2-6.12Z
</StreamGeometry>
<StreamGeometry x:Key="SemiIconTick">
M21.35 4.27c.68.47.86 1.4.38 2.08l-10 14.5a1.5 1.5 0 0 1-2.33.17l-6.5-7a1.5 1.5 0 0 1 2.2-2.04l5.23 5.63 8.94-12.96a1.5 1.5 0 0 1 2.08-.38Z
</StreamGeometry>
</ResourceDictionary>

View File

@@ -2,7 +2,16 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<Design.PreviewWith>
<StackPanel Height="300">
<u:MultiComboBox Width="300">
<u:MultiComboBoxItem Content="Option 1" />
<u:MultiComboBoxItem Content="Option 2" />
<u:MultiComboBoxItem Content="Option 3" />
<u:MultiComboBoxItem Content="Option 4" />
</u:MultiComboBox>
</StackPanel>
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type u:MultiComboBox}" TargetType="u:MultiComboBox">
<Setter Property="Focusable" Value="True" />
<Setter Property="VerticalAlignment" Value="Top" />
@@ -102,19 +111,20 @@
</Grid>
</Border>
<Popup
MinWidth="{Binding #PART_RootGrid.Bounds.Width}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
IsLightDismissEnabled="True"
IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
PlacementTarget="PART_RootGrid">
<Border
Margin="{DynamicResource ComboBoxPopupBorderMargin}"
HorizontalAlignment="Stretch"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{DynamicResource ComboBoxPopupBorderMargin}"
Padding="{DynamicResource ComboBoxPopupBorderPadding}"
Background="{DynamicResource ComboBoxPopupBackground}"
BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
CornerRadius="6">
CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}">
<DockPanel LastChildFill="True">
<ContentPresenter Content="{TemplateBinding PopupInnerTopContent}" DockPanel.Dock="Top" />
<ContentPresenter Content="{TemplateBinding PopupInnerBottomContent}" DockPanel.Dock="Bottom" />
@@ -208,7 +218,7 @@
</ControlTheme>
<ControlTheme x:Key="{x:Type u:MultiComboBoxItem}" TargetType="u:MultiComboBoxItem">
<Setter Property="Padding" Value="8,0,0,0" />
<Setter Property="Padding" Value="12 8" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Cursor" Value="Hand" />
@@ -220,6 +230,7 @@
<ControlTemplate TargetType="u:MultiComboBoxItem">
<Border
x:Name="RootBorder"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
@@ -231,20 +242,18 @@
Width="{DynamicResource CheckBoxBoxGlyphWidth}"
Height="{DynamicResource CheckBoxBoxGlyphHeight}"
Theme="{DynamicResource InnerPathIcon}"
Margin="8,0"
Margin="0 0 8 0"
VerticalAlignment="Center"
Data="{DynamicResource CheckBoxCheckGlyph}"
Data="{DynamicResource SemiIconTick}"
Opacity="0" />
<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content,
Converter={x:Static ObjectConverters.IsNotNull}}"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True"
TextWrapping="Wrap" />
</Grid>

View File

@@ -5,7 +5,20 @@
xmlns:converters1="clr-namespace:Ursa.Converters;assembly=Ursa"
xmlns:iri="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<Design.PreviewWith>
<StackPanel Height="300">
<u:TreeComboBox
Watermark="Please Select"
Width="300"
MaxHeight="200">
<u:TreeComboBoxItem Header="Option 1">
<u:TreeComboBoxItem Header="Inner Option 1" />
<u:TreeComboBoxItem Header="Inner Option 2" />
</u:TreeComboBoxItem>
<u:TreeComboBoxItem Header="Option 2" />
</u:TreeComboBox>
</StackPanel>
</Design.PreviewWith>
<converters:MarginMultiplierConverter
x:Key="LeftMarginConverter"
@@ -100,7 +113,6 @@
<Popup
Name="{x:Static iri:PartNames.PART_Popup}"
Grid.Column="0"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
ClipToBounds="False"
InheritsTransform="True"
@@ -110,12 +122,14 @@
WindowManagerAddShadowHint="False">
<Border
Name="PopupBorder"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{DynamicResource ComboBoxPopupBorderMargin}"
Padding="{DynamicResource ComboBoxPopupBorderPadding}"
Background="{DynamicResource ComboBoxPopupBackground}"
BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
CornerRadius="6">
CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}">
<DockPanel LastChildFill="True">
<ContentPresenter
Name="PART_PopupHeader"