月更
This commit is contained in:
133
AntDesignWPF/Styles/TextBox.xaml
Normal file
133
AntDesignWPF/Styles/TextBox.xaml
Normal file
@@ -0,0 +1,133 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:controls="clr-namespace:AntDesign.WPF.Controls"
|
||||
xmlns:helpers="clr-namespace:AntDesign.WPF.Helpers"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesign.WPF;component/Styles/Converters.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesign.WPF;component/Styles/Animations.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesign.WPF;component/Styles/Input.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style
|
||||
BasedOn="{StaticResource Ant.Input}"
|
||||
TargetType="{x:Type TextBox}"
|
||||
x:Key="Ant.TextBox">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TextBox}">
|
||||
<Grid>
|
||||
<!-- Input Effect -->
|
||||
<Border
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{DynamicResource OutlineThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}"
|
||||
Focusable="False"
|
||||
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
Opacity="0"
|
||||
x:Name="Effect" />
|
||||
<!-- Input -->
|
||||
<controls:AntdBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderStyle="{TemplateBinding helpers:AntdControl.BorderStyle}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
UseLayoutRounding="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Input -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<!-- Suffix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding helpers:Input.Prefix}"
|
||||
Focusable="False"
|
||||
Grid.Column="0"
|
||||
Margin="1,0,5,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Prefix" />
|
||||
<!-- Placeholder -->
|
||||
<TextBlock
|
||||
Focusable="False"
|
||||
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Text="{TemplateBinding helpers:Input.Placeholder}"
|
||||
TextAlignment="{TemplateBinding TextAlignment}"
|
||||
TextWrapping="{TemplateBinding TextWrapping}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Visibility="Collapsed"
|
||||
x:Name="Placeholder" />
|
||||
<!-- Input -->
|
||||
<!-- TextBox will automatically handle padding, so you need to change the margin to a negative value. -->
|
||||
<ScrollViewer
|
||||
Background="{x:Null}"
|
||||
BorderThickness="0"
|
||||
Grid.Column="1"
|
||||
IsTabStop="False"
|
||||
Margin="{Binding Padding, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
x:Name="PART_ContentHost" />
|
||||
<!-- Suffix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding helpers:Input.Suffix}"
|
||||
Focusable="False"
|
||||
Grid.Column="2"
|
||||
Margin="5,0,1,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Suffix" />
|
||||
</Grid>
|
||||
</controls:AntdBorder>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="FocusStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" />
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState Storyboard="{StaticResource Ant.InputAnimating}" x:Name="Focused" />
|
||||
<VisualState x:Name="Unfocused" />
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Text, Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="">
|
||||
<Setter Property="Visibility" TargetName="Placeholder" Value="Visible" />
|
||||
</DataTrigger>
|
||||
<!-- Prefix & Suffix -->
|
||||
<Trigger Property="Content" SourceName="Prefix" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="Prefix" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="Content" SourceName="Suffix" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="Suffix" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="helpers:Input.Clearable" Value="True" />
|
||||
<Condition Property="Visibility" SourceName="Placeholder" Value="Collapsed" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Content" TargetName="Suffix">
|
||||
<!--
|
||||
How to customize Icon?
|
||||
By setting up the locally-defined resource dictionary.
|
||||
-->
|
||||
<Setter.Value>
|
||||
<controls:Icon
|
||||
Style="{StaticResource Ant.Clearable}"
|
||||
Type="close"
|
||||
helpers:Input.ClearEnabled="True" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user