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"> <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 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>
<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> </ResourceDictionary>

View File

@@ -2,7 +2,16 @@
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa"> 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"> <ControlTheme x:Key="{x:Type u:MultiComboBox}" TargetType="u:MultiComboBox">
<Setter Property="Focusable" Value="True" /> <Setter Property="Focusable" Value="True" />
<Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalAlignment" Value="Top" />
@@ -42,18 +51,18 @@
IsVisible="{TemplateBinding InnerLeftContent, IsVisible="{TemplateBinding InnerLeftContent,
Converter={x:Static ObjectConverters.IsNotNull}}" /> Converter={x:Static ObjectConverters.IsNotNull}}" />
<TextBlock <TextBlock
x:Name="PlaceholderTextBlock" x:Name="PlaceholderTextBlock"
Grid.Column="1" Grid.Column="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Margin="{TemplateBinding Padding}" Margin="{TemplateBinding Padding}"
TextTrimming="CharacterEllipsis" TextTrimming="CharacterEllipsis"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
IsHitTestVisible="False" IsHitTestVisible="False"
IsVisible="False" IsVisible="False"
Opacity="0.3" Opacity="0.3"
Text="{TemplateBinding Watermark}" /> Text="{TemplateBinding Watermark}" />
<ScrollViewer <ScrollViewer
Grid.Column="1" Grid.Column="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
@@ -102,22 +111,23 @@
</Grid> </Grid>
</Border> </Border>
<Popup <Popup
MinWidth="{Binding #PART_RootGrid.Bounds.Width}"
MaxHeight="{TemplateBinding MaxDropDownHeight}" MaxHeight="{TemplateBinding MaxDropDownHeight}"
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}" IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
PlacementTarget="PART_RootGrid"> PlacementTarget="PART_RootGrid">
<Border <Border
Margin="{DynamicResource ComboBoxPopupBorderMargin}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{DynamicResource ComboBoxPopupBorderMargin}"
Padding="{DynamicResource ComboBoxPopupBorderPadding}"
Background="{DynamicResource ComboBoxPopupBackground}" Background="{DynamicResource ComboBoxPopupBackground}"
BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}" BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}" BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}" BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
CornerRadius="6"> CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}">
<DockPanel LastChildFill="True"> <DockPanel LastChildFill="True">
<ContentPresenter Content="{TemplateBinding PopupInnerTopContent}" DockPanel.Dock="Top"/> <ContentPresenter Content="{TemplateBinding PopupInnerTopContent}" DockPanel.Dock="Top" />
<ContentPresenter Content="{TemplateBinding PopupInnerBottomContent}" DockPanel.Dock="Bottom"/> <ContentPresenter Content="{TemplateBinding PopupInnerBottomContent}" DockPanel.Dock="Bottom" />
<ScrollViewer <ScrollViewer
Grid.IsSharedSizeScope="True" Grid.IsSharedSizeScope="True"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
@@ -208,7 +218,7 @@
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="{x:Type u:MultiComboBoxItem}" TargetType="u:MultiComboBoxItem"> <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="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Cursor" Value="Hand" /> <Setter Property="Cursor" Value="Hand" />
@@ -220,6 +230,7 @@
<ControlTemplate TargetType="u:MultiComboBoxItem"> <ControlTemplate TargetType="u:MultiComboBoxItem">
<Border <Border
x:Name="RootBorder" x:Name="RootBorder"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
@@ -231,20 +242,18 @@
Width="{DynamicResource CheckBoxBoxGlyphWidth}" Width="{DynamicResource CheckBoxBoxGlyphWidth}"
Height="{DynamicResource CheckBoxBoxGlyphHeight}" Height="{DynamicResource CheckBoxBoxGlyphHeight}"
Theme="{DynamicResource InnerPathIcon}" Theme="{DynamicResource InnerPathIcon}"
Margin="8,0" Margin="0 0 8 0"
VerticalAlignment="Center" VerticalAlignment="Center"
Data="{DynamicResource CheckBoxCheckGlyph}" Data="{DynamicResource SemiIconTick}"
Opacity="0" /> Opacity="0" />
<ContentPresenter <ContentPresenter
x:Name="ContentPresenter" x:Name="ContentPresenter"
Grid.Column="1" Grid.Column="1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="{TemplateBinding Content}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content, IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}"
Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True" RecognizesAccessKey="True"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</Grid> </Grid>

View File

@@ -5,7 +5,20 @@
xmlns:converters1="clr-namespace:Ursa.Converters;assembly=Ursa" xmlns:converters1="clr-namespace:Ursa.Converters;assembly=Ursa"
xmlns:iri="https://irihi.tech/shared" xmlns:iri="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa"> 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 <converters:MarginMultiplierConverter
x:Key="LeftMarginConverter" x:Key="LeftMarginConverter"
@@ -100,7 +113,6 @@
<Popup <Popup
Name="{x:Static iri:PartNames.PART_Popup}" Name="{x:Static iri:PartNames.PART_Popup}"
Grid.Column="0" Grid.Column="0"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
MaxHeight="{TemplateBinding MaxDropDownHeight}" MaxHeight="{TemplateBinding MaxDropDownHeight}"
ClipToBounds="False" ClipToBounds="False"
InheritsTransform="True" InheritsTransform="True"
@@ -110,12 +122,14 @@
WindowManagerAddShadowHint="False"> WindowManagerAddShadowHint="False">
<Border <Border
Name="PopupBorder" Name="PopupBorder"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{DynamicResource ComboBoxPopupBorderMargin}" Margin="{DynamicResource ComboBoxPopupBorderMargin}"
Padding="{DynamicResource ComboBoxPopupBorderPadding}"
Background="{DynamicResource ComboBoxPopupBackground}" Background="{DynamicResource ComboBoxPopupBackground}"
BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}" BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}" BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}" BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
CornerRadius="6"> CornerRadius="{DynamicResource ComboBoxPopupBoxCornerRadius}">
<DockPanel LastChildFill="True"> <DockPanel LastChildFill="True">
<ContentPresenter <ContentPresenter
Name="PART_PopupHeader" Name="PART_PopupHeader"