Files
ShrlAlgoToolkit/Melskin/Controls/AutoComplete.xaml

100 lines
6.6 KiB
Plaintext
Raw Normal View History

2025-08-20 12:10:35 +08:00
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2026-01-02 17:30:41 +08:00
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:controls="clr-namespace:Melskin.Controls"
xmlns:converters="clr-namespace:Melskin.Converters"
2026-01-02 17:30:30 +08:00
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="FlattenTextBox.xaml" />
</ResourceDictionary.MergedDictionaries>-->
2025-12-23 21:35:54 +08:00
<Style TargetType="{x:Type controls:AutoComplete}">
2025-12-23 21:35:54 +08:00
<Setter Property="assists:InputAssist.PlaceholderText" Value="请输入..." />
2025-08-20 12:10:35 +08:00
<Setter Property="assists:InputAssist.Clearable" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:AutoComplete}">
2025-08-20 12:10:35 +08:00
<Grid>
<TextBox
2026-01-02 17:30:30 +08:00
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
2025-08-20 12:10:35 +08:00
assists:InputAssist.Clearable="{TemplateBinding assists:InputAssist.Clearable}"
2025-12-23 21:35:54 +08:00
assists:InputAssist.PlaceholderText="{TemplateBinding assists:InputAssist.PlaceholderText}"
2026-01-02 17:30:30 +08:00
x:Name="PART_TextBox" />
2025-08-20 12:10:35 +08:00
<Popup
AllowsTransparency="True"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
2026-01-02 17:30:30 +08:00
MinWidth="{Binding ActualWidth, ElementName=PART_TextBox}"
2025-08-20 12:10:35 +08:00
PlacementTarget="{Binding ElementName=PART_TextBox}"
PopupAnimation="Slide"
2026-01-02 17:30:30 +08:00
StaysOpen="True"
assists:BehaviorAssist.SimulateNativeBehavior="True"
x:Name="PART_Popup">
2025-08-20 12:10:35 +08:00
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="6"
2026-01-02 17:30:30 +08:00
Effect="{DynamicResource PopupShadow}"
Margin="0,8,0,0"
MinHeight="30">
2025-08-20 12:10:35 +08:00
<!--<Border.Effect>
<DropShadowEffect
BlurRadius="10"
Opacity="0.1"
ShadowDepth="0"
Color="Black" />
</Border.Effect>-->
<ListBox
BorderThickness="0"
2026-01-02 17:30:30 +08:00
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
x:Name="PART_ListBox">
2025-08-20 12:10:35 +08:00
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="12,5,12,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border
2025-12-23 21:35:54 +08:00
Background="{TemplateBinding Background}"
2026-01-02 17:30:30 +08:00
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true"
x:Name="Bd">
2025-08-20 12:10:35 +08:00
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
2025-08-20 12:10:35 +08:00
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundHoverBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
<Trigger Property="IsSelected" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter>
<ContentPresenter.Content>
<MultiBinding Converter="{x:Static converters:StringMatchConverter.Instance}">
<Binding />
<Binding Path="Text" RelativeSource="{RelativeSource AncestorType=controls:AutoComplete}" />
2025-08-20 12:10:35 +08:00
</MultiBinding>
</ContentPresenter.Content>
</ContentPresenter>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>