Files
ShrlAlgoToolkit/Melskin/Controls/AutoComplete.xaml
2026-02-17 22:17:13 +08:00

100 lines
6.6 KiB
XML

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