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