add TextBox control

now you can clear and verify the text of textbox
This commit is contained in:
NaBian committed 2018-11-08 14:28:23 +08:00
1 parent 9c5174c7a2
commit bc2bd5413c
35 files changed
+369 -135

No files matched your search

+12 -1
View File
@@ -98,7 +98,7 @@ namespace HandyControl.Controls
#region Public Properties
public static readonly DependencyProperty SelectedTimeProperty = DependencyProperty.Register(
"SelectedTime", typeof(DateTime?), typeof(Clock), new PropertyMetadata(default(DateTime), OnSelectedTimeChanged));
"SelectedTime", typeof(DateTime?), typeof(Clock), new PropertyMetadata(default(DateTime?), OnSelectedTimeChanged));
private static void OnSelectedTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
@@ -239,6 +239,17 @@ namespace HandyControl.Controls
}
_appliedTemplate = true;
if (_isLoaded)
{
if (SelectedTime.HasValue)
{
Update(SelectedTime.Value);
}
else
{
DisplayTime = DateTime.Now;
}
}
}
#endregion Public Methods
@@ -9,7 +9,6 @@ using HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools.Extension;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
/// <summary>
@@ -359,6 +358,8 @@ namespace HandyControl.Controls
_sliderOpacity.ValueChanged -= SliderOpacity_OnValueChanged;
}
_panelColor?.Children.Clear();
_panelRgb?.RemoveHandler(NumericUpDown.ValueChangedEvent, new EventHandler<FunctionEventArgs<double>>(NumericUpDownRgb_OnValueChanged));
base.OnApplyTemplate();
@@ -391,6 +392,10 @@ namespace HandyControl.Controls
collection.Add(behavior);
}
if (_isLoaded)
{
Init();
}
_panelRgb?.AddHandler(NumericUpDown.ValueChangedEvent, new EventHandler<FunctionEventArgs<double>>(NumericUpDownRgb_OnValueChanged));
}
-23
View File
@@ -1,23 +0,0 @@
using System;
using HandyControl.Data;
namespace HandyControl.Controls
{
/// <summary>
/// 表示可以成为一个数据输入控件
/// </summary>
public interface IDataInput
{
bool VerifyData();
Func<string, OperationResult<bool>> VerifyFunc { get; set; }
bool IsError { get; set; }
string ErrorStr { get; set; }
TextType TextType { get; set; }
bool ShowClearButton { get; set; }
}
}
+43
View File
@@ -0,0 +1,43 @@
using System;
using HandyControl.Data;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
/// <summary>
/// 表示可以成为一个数据输入控件
/// </summary>
public interface IDataInput
{
/// <summary>
/// 验证数据
/// </summary>
/// <returns></returns>
bool VerifyData();
/// <summary>
/// 数据验证委托
/// </summary>
Func<string, OperationResult<bool>> VerifyFunc { get; set; }
/// <summary>
/// 数据是否错误
/// </summary>
bool IsError { get; set; }
/// <summary>
/// 错误提示
/// </summary>
string ErrorStr { get; set; }
/// <summary>
/// 文本类型
/// </summary>
TextType TextType { get; set; }
/// <summary>
/// 是否显示清除按钮
/// </summary>
bool ShowClearButton { get; set; }
}
}
@@ -5,8 +5,10 @@ using System.Windows.Input;
using HandyControl.Data;
using HandyControl.Interactivity;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
/// <inheritdoc cref="IDataInput" />
/// <summary>
/// 数值选择控件
/// </summary>
@@ -25,6 +27,11 @@ namespace HandyControl.Controls
#endregion Data
static NumericUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), new FrameworkPropertyMetadata(typeof(NumericUpDown)));
}
public NumericUpDown()
{
CommandBindings.Add(new CommandBinding(ControlCommands.Prev, (s, e) =>
@@ -44,6 +51,8 @@ namespace HandyControl.Controls
ClearValue(ValueProperty);
_textBox.Text = string.Empty;
}));
Loaded += (s, e) => OnApplyTemplate();
}
protected override void OnGotFocus(RoutedEventArgs e)
@@ -309,9 +318,6 @@ namespace HandyControl.Controls
public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register(
"IsError", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(default(bool)));
/// <summary>
/// 数据是否错误
/// </summary>
public bool IsError
{
get => (bool) GetValue(IsErrorProperty);
@@ -324,9 +330,6 @@ namespace HandyControl.Controls
public static readonly DependencyProperty ErrorStrProperty = DependencyProperty.Register(
"ErrorStr", typeof(string), typeof(NumericUpDown), new PropertyMetadata(default(string)));
/// <summary>
/// 错误提示
/// </summary>
public string ErrorStr
{
get => (string) GetValue(ErrorStrProperty);
@@ -339,9 +342,6 @@ namespace HandyControl.Controls
public static readonly DependencyProperty TextTypeProperty = DependencyProperty.Register(
"TextType", typeof(TextType), typeof(NumericUpDown), new PropertyMetadata(default(TextType)));
/// <summary>
/// 文本类型
/// </summary>
public TextType TextType
{
get => (TextType) GetValue(TextTypeProperty);
@@ -354,24 +354,14 @@ namespace HandyControl.Controls
public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register(
"ShowClearButton", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(default(bool)));
/// <summary>
/// 是否显示清除按钮
/// </summary>
public bool ShowClearButton
{
get => (bool) GetValue(ShowClearButtonProperty);
set => SetValue(ShowClearButtonProperty, value);
}
/// <summary>
/// 数据验证委托
/// </summary>
public Func<string, OperationResult<bool>> VerifyFunc { get; set; }
/// <summary>
/// 验证数据
/// </summary>
/// <returns></returns>
public virtual bool VerifyData()
{
OperationResult<bool> result;
+110 -3
View File
@@ -1,8 +1,115 @@
// ReSharper disable once CheckNamespace
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
public class TextBox : System.Windows.Controls.TextBox
public class TextBox : System.Windows.Controls.TextBox, IDataInput
{
public TextBox()
{
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
{
ClearValue(TextProperty);
Text = string.Empty;
}));
}
protected override void OnTextChanged(TextChangedEventArgs e)
{
base.OnTextChanged(e);
VerifyData();
}
public Func<string, OperationResult<bool>> VerifyFunc { get; set; }
/// <summary>
/// 数据是否错误
/// </summary>
public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register(
"IsError", typeof(bool), typeof(TextBox), new PropertyMetadata(default(bool)));
public bool IsError
{
get => (bool) GetValue(IsErrorProperty);
set => SetValue(IsErrorProperty, value);
}
/// <summary>
/// 错误提示
/// </summary>
public static readonly DependencyProperty ErrorStrProperty = DependencyProperty.Register(
"ErrorStr", typeof(string), typeof(TextBox), new PropertyMetadata(default(string)));
public string ErrorStr
{
get => (string) GetValue(ErrorStrProperty);
set => SetValue(ErrorStrProperty, value);
}
/// <summary>
/// 文本类型
/// </summary>
public static readonly DependencyProperty TextTypeProperty = DependencyProperty.Register(
"TextType", typeof(TextType), typeof(TextBox), new PropertyMetadata(default(TextType)));
public TextType TextType
{
get => (TextType) GetValue(TextTypeProperty);
set => SetValue(TextTypeProperty, value);
}
/// <summary>
/// 是否显示清除按钮
/// </summary>
public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register(
"ShowClearButton", typeof(bool), typeof(TextBox), new PropertyMetadata(default(bool)));
public bool ShowClearButton
{
get => (bool) GetValue(ShowClearButtonProperty);
set => SetValue(ShowClearButtonProperty, value);
}
public virtual bool VerifyData()
{
OperationResult<bool> result;
if (VerifyFunc != null)
{
result = VerifyFunc.Invoke(Text);
}
else
{
if (!string.IsNullOrEmpty(Text))
{
if (TextType != TextType.Common)
{
result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError);
}
else
{
result = OperationResult.Success();
}
}
else if (InfoElement.GetNecessary(this))
{
result = OperationResult.Failed(Properties.Langs.Lang.IsNecessary);
}
else
{
result = OperationResult.Success();
}
}
IsError = !result.Data;
ErrorStr = result.Message;
return result.Data;
}
}
}
@@ -7,9 +7,6 @@ using System.Windows.Shapes;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
/// <summary>
/// LoadingLine.xaml 的交互逻辑
/// </summary>
public class LoadingLine : LoadingBase
{
private const double MoveLength = 80;
+6
View File
@@ -67,12 +67,18 @@ namespace HandyControl.Controls
public override void OnApplyTemplate()
{
_panelMain?.Children.Clear();
base.OnApplyTemplate();
_progressBarBack = GetTemplateChild(ElementProgressBarBack) as ProgressBar;
_panelMain = GetTemplateChild(ElementUniformGridMain) as Panel;
CheckNull();
if (_isLoaded)
{
UpdateItems(Items);
}
}
private void CheckNull()
+7 -1
View File
@@ -150,12 +150,14 @@ namespace HandyControl.Controls
/// </summary>
private double _totalOffsetX;
private readonly bool _isLoaded;
public TimeBar()
{
_starTime = DateTime.Now;
SelectedTime = new DateTime(_starTime.Year, _starTime.Month, _starTime.Day, 0, 0, 0);
_starTime = SelectedTime;
_isLoaded = true;
SizeChanged += TimeBar_OnSizeChanged;
MouseMove += TimeBar_OnMouseMove;
}
@@ -188,6 +190,10 @@ namespace HandyControl.Controls
var collection = Interaction.GetBehaviors(_borderTop);
collection.Add(behavior);
if (_isLoaded)
{
TimeBar_OnSizeChanged(null, null);
}
_textBlockSelected.Text = SelectedTime.ToString(TimeFormat);
}
+4 -4
View File
@@ -51,14 +51,14 @@
<Compile Include="Controls\Clock\Clock.cs" />
<Compile Include="Controls\Clock\ClockRadioButton.cs" />
<Compile Include="Controls\Growl.cs" />
<Compile Include="Controls\IDataInput.cs" />
<Compile Include="Controls\Input\IDataInput.cs" />
<Compile Include="Controls\Input\TextBox.cs" />
<Compile Include="Controls\ISingleOpen.cs" />
<Compile Include="Controls\NumericUpDown.cs" />
<Compile Include="Controls\Input\NumericUpDown.cs" />
<Compile Include="Controls\Pagination.cs" />
<Compile Include="Controls\Attach\IconElement.cs" />
<Compile Include="Controls\Slider\CompareSlider.cs" />
<Compile Include="Controls\Picker\ColorPicker.cs" />
<Compile Include="Controls\ColorPicker.cs" />
<Compile Include="Controls\Slider\PreviewSlider.cs" />
<Compile Include="Controls\ScrollViewer.cs" />
<Compile Include="Controls\Loading\LoadingBase.cs" />
@@ -116,7 +116,7 @@
<Compile Include="Controls\TabControl\TabItem.cs" />
<Compile Include="Controls\TabControl\TabPanel.cs" />
<Compile Include="Controls\TimeBar\SpeTextBlock.cs" />
<Compile Include="Controls\Picker\TimePicker.cs" />
<Compile Include="Controls\Input\TimePicker.cs" />
<Compile Include="Controls\TimeBar\TimeBar.cs" />
<Compile Include="Controls\TransitioningContentControl.cs" />
<Compile Include="Controls\WatermarkTextBox.cs" />
+4 -6
View File
@@ -452,7 +452,7 @@
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Background="Transparent" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
<Rectangle Fill="{TemplateBinding Background}" Height="2"/>
<Rectangle StrokeThickness="0" Fill="{TemplateBinding Background}" Height="2"/>
</Border>
</ControlTemplate>
</Setter.Value>
@@ -468,7 +468,7 @@
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Background="Transparent" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
<Rectangle Fill="{TemplateBinding Background}" Width="2"/>
<Rectangle StrokeThickness="0" Fill="{TemplateBinding Background}" Width="2"/>
</Border>
</ControlTemplate>
</Setter.Value>
@@ -646,7 +646,7 @@
<RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource SliderRepeatButtonHorizontalStyle}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb ClipToBounds="False" Width="18" Margin="-9,0,-9,0" Height="18" x:Name="Thumb" Focusable="False" OverridesDefaultStyle="True" Template="{StaticResource SliderThumb}" VerticalAlignment="Center"/>
<Thumb ClipToBounds="False" Width="18" Margin="-9,0" Height="18" x:Name="Thumb" Focusable="False" OverridesDefaultStyle="True" Template="{StaticResource SliderThumb}" VerticalAlignment="Center"/>
</Track.Thumb>
</Track>
</Grid>
@@ -701,7 +701,7 @@
<RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource SliderRepeatButtonVerticalStyle}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb Margin="0,-9" x:Name="Thumb" Focusable="False" Height="18" OverridesDefaultStyle="True" Template="{StaticResource SliderThumb}" VerticalAlignment="Top" Width="18"/>
<Thumb Margin="0,-9" x:Name="Thumb" Focusable="False" Height="18" OverridesDefaultStyle="True" Template="{StaticResource SliderThumb}" HorizontalAlignment="Center" Width="18"/>
</Track.Thumb>
</Track>
</Grid>
@@ -722,11 +722,9 @@
</MultiTrigger>
<Trigger Property="TickPlacement" Value="TopLeft">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="2,5,0,5"/>
</Trigger>
<Trigger Property="TickPlacement" Value="BottomRight">
<Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="0,5,2,5"/>
</Trigger>
<Trigger Property="TickPlacement" Value="Both">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
+86 -17
View File
@@ -1,9 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib">
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Basic/Geometries.xaml"/>
<ResourceDictionary Source="Button.xaml"/>
<ResourceDictionary Source="Base/TextBoxBaseStyle.xaml"/>
<ResourceDictionary Source="TextBlock.xaml"/>
</ResourceDictionary.MergedDictionaries>
@@ -80,55 +83,121 @@
</Style>
<ControlTemplate x:Key="TextBoxPlusTopTemplate" TargetType="controls:TextBox">
<ControlTemplate.Resources>
<Storyboard x:Key="StoryboardShow">
<ThicknessAnimation Storyboard.TargetName="TextBlockError" Storyboard.TargetProperty="Margin" To="8,0,0,-18" Duration="0:0:.2"/>
</Storyboard>
<Storyboard x:Key="StoryboardHidden">
<ThicknessAnimation Storyboard.TargetName="TextBlockError" Storyboard.TargetProperty="Margin" To="8,0,0,4" Duration="0:0:0"/>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Path=(controls:InfoElement.ContentHeight),RelativeSource={RelativeSource TemplatedParent}}"/>
</Grid.RowDefinitions>
<StackPanel Visibility="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource String2VisibilityConverter}}" Orientation="Horizontal" Margin="7,4">
<TextBlock Text="{TemplateBinding ErrorStr}" Name="TextBlockError" VerticalAlignment="Bottom" Margin="8,0,0,4" Foreground="{DynamicResource DangerBrush}" Grid.Row="1"/>
<StackPanel Grid.Row="0" Visibility="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource String2VisibilityConverter}}" Orientation="Horizontal" Margin="7,4">
<TextBlock Foreground="{DynamicResource PrimaryTextBrush}" Margin="1,0,0,0" Text="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent}}"/>
<ContentPresenter TextElement.Foreground="{DynamicResource DangerBrush}" Margin="4,0,0,0" Content="{Binding Path=(controls:InfoElement.Symbol),RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding Path=(controls:InfoElement.Necessary),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}"/>
</StackPanel>
<Border x:Name="border" Grid.Row="1" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"/>
<TextBlock VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="8" Grid.Row="1" Visibility="{TemplateBinding Text,Converter={StaticResource String2VisibilityReConverter}}" HorizontalAlignment="Stretch" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}"/>
<ScrollViewer Padding="7,0" Margin="1,1,1,2" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Grid.Row="1" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<Border Grid.Row="1" x:Name="templateRoot" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="7,8" Visibility="{TemplateBinding Text,Converter={StaticResource String2VisibilityReConverter}}" HorizontalAlignment="Stretch" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}"/>
<ScrollViewer Grid.Column="0" Padding="7,0" Margin="0,0,0,1" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<Button Command="interactivity:ControlCommands.Clear" Margin="0,0,7,0" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.4"/>
<Setter Property="Opacity" TargetName="templateRoot" Value="0.4"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true" SourceName="PART_ContentHost">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource SecondaryBorderBrush}"/>
<Trigger Property="IsMouseOver" Value="true" SourceName="templateRoot">
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderBrush}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true" SourceName="templateRoot"/>
<Condition Property="ShowClearButton" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" TargetName="ButtonClear"/>
</MultiTrigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryBrush}"/>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource PrimaryBrush}"/>
</Trigger>
<Trigger Property="IsError" Value="true">
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource DangerBrush}"/>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource StoryboardShow}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource StoryboardHidden}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="TextBoxPlusLeftTemplate" TargetType="controls:TextBox">
<ControlTemplate.Resources>
<Storyboard x:Key="StoryboardShow">
<ThicknessAnimation Storyboard.TargetName="TextBlockError" Storyboard.TargetProperty="Margin" To="8,0,0,-18" Duration="0:0:.2"/>
</Storyboard>
<Storyboard x:Key="StoryboardHidden">
<ThicknessAnimation Storyboard.TargetName="TextBlockError" Storyboard.TargetProperty="Margin" To="8,0,0,4" Duration="0:0:0"/>
</Storyboard>
</ControlTemplate.Resources>
<Grid Height="{Binding Path=(controls:InfoElement.ContentHeight),RelativeSource={RelativeSource TemplatedParent}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding Path=(controls:InfoElement.TitleWidth),RelativeSource={RelativeSource TemplatedParent}}"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Visibility="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource String2VisibilityConverter}}" Orientation="Horizontal" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0,7,6,8">
<TextBlock Text="{TemplateBinding ErrorStr}" Name="TextBlockError" VerticalAlignment="Bottom" Margin="8,0,0,4" Foreground="{DynamicResource DangerBrush}" Grid.Column="1"/>
<StackPanel Grid.Column="0" Visibility="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource String2VisibilityConverter}}" Orientation="Horizontal" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0,7,6,8">
<TextBlock Foreground="{DynamicResource PrimaryTextBrush}" Text="{Binding Path=(controls:InfoElement.Title),RelativeSource={RelativeSource TemplatedParent}}"/>
<ContentPresenter TextElement.Foreground="{DynamicResource DangerBrush}" Margin="4,0,0,0" Content="{Binding Path=(controls:InfoElement.Symbol),RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding Path=(controls:InfoElement.Necessary),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}"/>
</StackPanel>
<Border x:Name="border" Grid.Column="1" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"/>
<TextBlock VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="8,7,8,8" Grid.Column="1" Visibility="{TemplateBinding Text,Converter={StaticResource String2VisibilityReConverter}}" HorizontalAlignment="Stretch" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}"/>
<ScrollViewer Grid.Column="1" Padding="7,0" Margin="1,1,1,2" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<Border Grid.Column="1" x:Name="templateRoot" CornerRadius="{Binding Path=(controls:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="7,8" Visibility="{TemplateBinding Text,Converter={StaticResource String2VisibilityReConverter}}" HorizontalAlignment="Stretch" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Path=(controls:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}"/>
<ScrollViewer Grid.Column="0" Padding="7,0" Margin="0,0,0,1" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<Button Command="interactivity:ControlCommands.Clear" Margin="0,0,7,0" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" controls:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.4"/>
<Setter Property="Opacity" TargetName="templateRoot" Value="0.4"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true" SourceName="PART_ContentHost">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource SecondaryBorderBrush}"/>
<Trigger Property="IsMouseOver" Value="true" SourceName="templateRoot">
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderBrush}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true" SourceName="templateRoot"/>
<Condition Property="ShowClearButton" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" TargetName="ButtonClear"/>
</MultiTrigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryBrush}"/>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource PrimaryBrush}"/>
</Trigger>
<Trigger Property="IsError" Value="true">
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource DangerBrush}"/>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource StoryboardShow}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource StoryboardHidden}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
+3 -1
View File
@@ -38,6 +38,8 @@
public static readonly string CircleProgressBarDemoCtl = nameof(CircleProgressBarDemoCtl);
public static readonly string TextBoxDemoCtl = nameof(TextBoxDemoCtl);
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl);
@@ -52,7 +54,7 @@
public static readonly string DatePickerDemoCtl = nameof(DatePickerDemoCtl);
public static readonly string TextBoxDemoCtl = nameof(TextBoxDemoCtl);
public static readonly string NaiveTextBoxDemoCtl = nameof(NaiveTextBoxDemoCtl);
public static readonly string TextBlockDemoCtl = nameof(TextBlockDemoCtl);
+3 -2
View File
@@ -21,7 +21,8 @@ var controlList = new List<string>
"WindowDemoCtl",
"ScrollViewerDemoCtl",
"PreviewSliderDemoCtl",
"CircleProgressBarDemoCtl"
"CircleProgressBarDemoCtl",
"TextBoxDemoCtl"
};
var styleList = new List<string>
{
@@ -32,7 +33,7 @@ var styleList = new List<string>
"TabControlDemoCtl",
"CalendarDemoCtl",
"DatePickerDemoCtl",
"TextBoxDemoCtl",
"NaiveTextBoxDemoCtl",
"TextBlockDemoCtl",
"ComboBoxDemoCtl",
"PasswordBoxDemoCtl",
+10 -3
View File
@@ -137,6 +137,9 @@
<Compile Include="UserControl\Controls\StepBarDemoCtl.xaml.cs">
<DependentUpon>StepBarDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\TextBoxDemoCtl.xaml.cs">
<DependentUpon>TextBoxDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\TimePickerDemoCtl.xaml.cs">
<DependentUpon>TimePickerDemoCtl.xaml</DependentUpon>
</Compile>
@@ -218,8 +221,8 @@
<Compile Include="UserControl\Styles\TextBlockDemoCtl.xaml.cs">
<DependentUpon>TextBlockDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Styles\TextBoxDemoCtl.xaml.cs">
<DependentUpon>TextBoxDemoCtl.xaml</DependentUpon>
<Compile Include="UserControl\Styles\NaiveTextBoxDemoCtl.xaml.cs">
<DependentUpon>NaiveTextBoxDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Styles\ToggleButtonDemoCtl.xaml.cs">
<DependentUpon>ToggleButtonDemoCtl.xaml</DependentUpon>
@@ -356,6 +359,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\TextBoxDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\TimePickerDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -464,7 +471,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Styles\TextBoxDemoCtl.xaml">
<Page Include="UserControl\Styles\NaiveTextBoxDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+9
View File
@@ -600,6 +600,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 请输入邮箱 的本地化字符串。
/// </summary>
public static string PlsEnterEmail {
get {
return ResourceManager.GetString("PlsEnterEmail", resourceCulture);
}
}
/// <summary>
/// 查找类似 上一步 的本地化字符串。
/// </summary>
@@ -393,4 +393,7 @@
<data name="IsNotPhone" xml:space="preserve">
<value>It's not a phone number</value>
</data>
<data name="PlsEnterEmail" xml:space="preserve">
<value>please enter email</value>
</data>
</root>
@@ -373,4 +373,7 @@
<data name="IsNotPhone" xml:space="preserve">
<value>不是手机号码</value>
</data>
<data name="PlsEnterEmail" xml:space="preserve">
<value>请输入邮箱</value>
</data>
</root>
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// AnimationPathDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class AnimationPathDemoCtl
{
public AnimationPathDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// CarouselDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class CarouselDemoCtl
{
public CarouselDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ClockDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ClockDemoCtl
{
public ClockDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ColorPickerDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ColorPickerDemoCtl
{
public ColorPickerDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// CompareSliderDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class CompareSliderDemoCtl
{
public CompareSliderDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// LoadingDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class LoadingDemoCtl
{
public LoadingDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// PaginationDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class PaginationDemoCtl
{
public PaginationDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// TabControlDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class TabControlDemoCtl
{
public TabControlDemoCtl()
@@ -0,0 +1,18 @@
<UserControl x:Class="HandyControlDemo.UserControl.TextBoxDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="{DynamicResource RegionBrush}"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl">
<controls:TransitioningContentControl>
<StackPanel Margin="32">
<controls:TextBox ShowClearButton="True" Text="{x:Static langs:Lang.ContentDemoStr}"/>
<controls:TextBox Text="{x:Static langs:Lang.ContentDemoStr}" Margin="0,16,0,0" IsEnabled="False"/>
<controls:TextBox ShowClearButton="True" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr1}" Margin="0,32,0,0" Text="{x:Static langs:Lang.ContentDemoStr}"/>
<controls:TextBox TextType="Mail" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterEmail}" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr2}" controls:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<controls:TextBox Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr3}" Margin="0,32,0,0" Text="{x:Static langs:Lang.ContentDemoStr}"/>
<controls:TextBox ShowClearButton="True" Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterContent}" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr3}" controls:InfoElement.Necessary="True" Margin="0,16,0,0"/>
</StackPanel>
</controls:TransitioningContentControl>
</UserControl>
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// TextBoxDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class TextBoxDemoCtl
{
public TextBoxDemoCtl()
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// TimeBarDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class TimeBarDemoCtl
{
public TimeBarDemoCtl()
@@ -129,6 +129,11 @@
<Image Source="../../Resources/Img/LeftMainContent/NumericListBox_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.TextBoxDemoCtl}" Content="{x:Static langs:Lang.TextBox}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/TextBox_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Tag="{x:Static data:MessageToken.CirclePanelDemoCtl}" Content="{x:Static langs:Lang.CirclePanel}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/ColorWheel_16x.png"/>
@@ -0,0 +1,17 @@
<UserControl x:Class="HandyControlDemo.UserControl.NaiveTextBoxDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
Background="{DynamicResource RegionBrush}">
<controls:TransitioningContentControl>
<StackPanel Margin="32">
<TextBox Text="{Binding ContentDemoStr,Source={StaticResource LangProvider},Mode=OneWay}"/>
<TextBox Text="{Binding ContentDemoStr,Source={StaticResource LangProvider},Mode=OneWay}" Margin="0,16,0,0" IsEnabled="False"/>
<TextBox controls:InfoElement.Title="{Binding TitleDemoStr1,Source={StaticResource LangProvider}}" Style="{StaticResource TextBoxExtend}" Margin="0,32,0,0" Text="{Binding ContentDemoStr,Source={StaticResource LangProvider},Mode=OneWay}"/>
<TextBox controls:InfoElement.Placeholder="{Binding PlsEnterContent,Source={StaticResource LangProvider}}" controls:InfoElement.Title="{Binding TitleDemoStr2,Source={StaticResource LangProvider}}" Style="{StaticResource TextBoxExtend}" controls:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<TextBox Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{Binding TitleDemoStr3,Source={StaticResource LangProvider}}" Style="{StaticResource TextBoxExtend}" Margin="0,32,0,0" Text="{Binding ContentDemoStr,Source={StaticResource LangProvider},Mode=OneWay}"/>
<TextBox Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.Placeholder="{Binding PlsEnterContent,Source={StaticResource LangProvider}}" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{Binding TitleDemoStr3,Source={StaticResource LangProvider}}" controls:InfoElement.Necessary="True" Style="{StaticResource TextBoxExtend}" Margin="0,16,0,0"/>
</StackPanel>
</controls:TransitioningContentControl>
</UserControl>
@@ -0,0 +1,11 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
public partial class NaiveTextBoxDemoCtl
{
public NaiveTextBoxDemoCtl()
{
InitializeComponent();
}
}
}
@@ -1,9 +1,6 @@
// ReSharper disable once CheckNamespace
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ProgressBarDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ProgressBarDemoCtl
{
public ProgressBarDemoCtl()
@@ -1,18 +0,0 @@
<UserControl x:Class="HandyControlDemo.UserControl.TextBoxDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
Background="{DynamicResource RegionBrush}">
<controls:TransitioningContentControl>
<StackPanel Margin="32">
<TextBox Text="{x:Static langs:Lang.ContentDemoStr}"/>
<TextBox Text="{x:Static langs:Lang.ContentDemoStr}" Margin="0,16,0,0" IsEnabled="False"/>
<TextBox controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr1}" Style="{StaticResource TextBoxExtend}" Margin="0,32,0,0" Text="{x:Static langs:Lang.ContentDemoStr}"/>
<TextBox controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterContent}" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr2}" Style="{StaticResource TextBoxExtend}" controls:InfoElement.Necessary="True" Margin="0,16,0,0"/>
<TextBox Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr3}" Style="{StaticResource TextBoxExtend}" Margin="0,32,0,0" Text="{x:Static langs:Lang.ContentDemoStr}"/>
<TextBox Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterContent}" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr3}" controls:InfoElement.Necessary="True" Style="{StaticResource TextBoxExtend}" Margin="0,16,0,0"/>
</StackPanel>
</controls:TransitioningContentControl>
</UserControl>