ソースを参照

控件-补充带提示文案的TextBox : TextBoxWithTip

ZhouJieSheng 2 年 前
コミット
75c4f06c52

+ 49 - 0
PDF Office/CustomControl/TextBoxEx.cs

@@ -76,5 +76,54 @@ namespace PDF_Office.CustomControl
         public static readonly DependencyProperty MouseOverForegroundProperty =
      DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(TextBoxEx), new PropertyMetadata(new SolidColorBrush(Colors.Transparent)));
 
+
+
+        public bool IsError
+        {
+            get { return (bool)GetValue(IsErrorProperty); }
+            set { SetValue(IsErrorProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for IsError.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty IsErrorProperty =
+            DependencyProperty.Register("IsError", typeof(bool), typeof(TextBoxEx), new PropertyMetadata(false));
+
+
+
+
+        public Visibility ShowTipText
+        {
+            get { return (Visibility)GetValue(ShowTipTextProperty); }
+            set { SetValue(ShowTipTextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ShowTipText.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ShowTipTextProperty =
+            DependencyProperty.Register("ShowTipText", typeof(Visibility), typeof(TextBoxEx), new PropertyMetadata(Visibility.Collapsed));
+
+
+
+
+        public bool ShowTip
+        {
+            get { return (bool)GetValue(ShowTipProperty); }
+            set { SetValue(ShowTipProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ShowTip.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ShowTipProperty =
+            DependencyProperty.Register("ShowTip", typeof(bool), typeof(TextBoxEx), new PropertyMetadata(false));
+
+
+
+        public string TipText
+        {
+            get { return (string)GetValue(TipTextProperty); }
+            set { SetValue(TipTextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for TipText.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty TipTextProperty =
+            DependencyProperty.Register("TipText", typeof(string), typeof(TextBoxEx), new PropertyMetadata(""));
     }
 }

+ 46 - 0
PDF Office/CustomControl/TextBoxWithTip.xaml

@@ -0,0 +1,46 @@
+<UserControl
+    x:Class="PDF_Office.CustomControl.TextBoxWithTip"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:PDF_Office.CustomControl"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    d:DesignHeight="450"
+    d:DesignWidth="800"
+    mc:Ignorable="d">
+    <UserControl.Style>
+        <Style TargetType="{x:Type UserControl}">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate>
+                        <Grid>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="*" />
+                                <RowDefinition Height="20" />
+                            </Grid.RowDefinitions>
+                            <local:TextBoxEx
+                                x:Name="TextBox"
+                                IsError="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=IsError}"
+                                PlaceholderText="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=PlaceHoldText}"
+                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=Text}" />
+                            <TextBlock
+                                Name="TbTip"
+                                Grid.Row="1"
+                                Margin="0,2,0,0"
+                                FontFamily="Segoe UI"
+                                FontSize="12"
+                                Foreground="{StaticResource color.field.text.tips}"
+                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=TipText}"
+                                Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=ShowTip}" />
+                        </Grid>
+                        <ControlTemplate.Triggers>
+                            <Trigger SourceName="TextBox" Property="IsError" Value="True">
+                                <Setter TargetName="TbTip" Property="Foreground" Value="{StaticResource color.field.text.tips-error}" />
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Style>
+</UserControl>

+ 95 - 0
PDF Office/CustomControl/TextBoxWithTip.xaml.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PDF_Office.CustomControl
+{
+    /// <summary>
+    /// TextBoxWithTip.xaml 的交互逻辑
+    /// 带有tip文字的TextBox
+    /// </summary>
+    public partial class TextBoxWithTip : UserControl
+    {
+        public TextBoxWithTip()
+        {
+            InitializeComponent();
+        }
+
+
+
+        public string TipText
+        {
+            get { return (string)GetValue(TipTextProperty); }
+            set { SetValue(TipTextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for TipText.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty TipTextProperty =
+            DependencyProperty.Register("TipText", typeof(string), typeof(TextBoxWithTip), new PropertyMetadata(""));
+
+
+
+        public Visibility ShowTip
+        {
+            get { return (Visibility)GetValue(ShowTipProperty); }
+            set { SetValue(ShowTipProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ShowTip.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ShowTipProperty =
+            DependencyProperty.Register("ShowTip", typeof(Visibility), typeof(TextBoxWithTip), new PropertyMetadata(Visibility.Hidden));
+
+
+
+
+        public string Text
+        {
+            get { return (string)GetValue(TextProperty); }
+            set { SetValue(TextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty TextProperty =
+            DependencyProperty.Register("Text", typeof(string), typeof(TextBoxWithTip), new PropertyMetadata(null));
+
+
+
+        public string  PlaceHoldText
+        {
+            get { return (string )GetValue(PlaceHoldTextProperty); }
+            set { SetValue(PlaceHoldTextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for PlaceHoldText.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty PlaceHoldTextProperty =
+            DependencyProperty.Register("PlaceHoldText", typeof(string ), typeof(TextBoxWithTip), new PropertyMetadata(""));
+
+
+
+        public bool IsError
+        {
+            get { return (bool)GetValue(IsErrorProperty); }
+            set { SetValue(IsErrorProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for IsError.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty IsErrorProperty =
+            DependencyProperty.Register("IsError", typeof(bool), typeof(TextBoxWithTip), new PropertyMetadata(false));
+
+
+
+
+
+    }
+}

+ 7 - 0
PDF Office/PDF Office.csproj

@@ -227,6 +227,9 @@
     <Compile Include="CustomControl\SystemControl\CustomCommandAction .cs" />
     <Compile Include="CustomControl\SystemControl\RoutedEventTrigger.cs" />
     <Compile Include="CustomControl\TextBoxEx.cs" />
+    <Compile Include="CustomControl\TextBoxWithTip.xaml.cs">
+      <DependentUpon>TextBoxWithTip.xaml</DependentUpon>
+    </Compile>
     <Compile Include="CustomControl\ToastControl.xaml.cs">
       <DependentUpon>ToastControl.xaml</DependentUpon>
     </Compile>
@@ -890,6 +893,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="CustomControl\TextBoxWithTip.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="CustomControl\ToastControl.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

+ 5 - 5
PDF Office/Themes/Alias_Light.xaml

@@ -62,7 +62,7 @@
     <SolidColorBrush x:Key="color.btn.cta.bg.norm">#1770F4</SolidColorBrush>
     <SolidColorBrush x:Key="color.btn.cta.bg.hov">#3f8ff6</SolidColorBrush>
     <SolidColorBrush x:Key="color.btn.cta.bg.act">#0e53ca</SolidColorBrush>
-    <SolidColorBrush x:Key="color.btn.cta.bg.dis">#92C6FB</SolidColorBrush>
+    <SolidColorBrush x:Key="color.btn.cta.bg.dis">#BDDFFD</SolidColorBrush>
     <SolidColorBrush x:Key="color.btn.cta.text.def">#ffffff</SolidColorBrush>
     <SolidColorBrush x:Key="color.btn.cta.text.dis">#F7F8FA</SolidColorBrush>
     <SolidColorBrush x:Key="color.btn.brand.bg.norm">#273C62</SolidColorBrush>
@@ -214,28 +214,28 @@
     <DropShadowEffect
         x:Key="shadow.neutral.s"
         BlurRadius="2"
-        Direction="270"
+        Direction="0"
         Opacity=" 0.1"
         ShadowDepth="2"
         Color="#000000" />
     <DropShadowEffect
         x:Key="shadow.neutral.m"
         BlurRadius="8"
-        Direction="270"
+        Direction="0 "
         Opacity=" 0.16"
         ShadowDepth="2"
         Color="#000000" />
     <DropShadowEffect
         x:Key="shadow.accent.s"
         BlurRadius="4"
-        Direction="270"
+        Direction="0"
         Opacity="0.4"
         ShadowDepth="0"
         Color="#1770F4" />
     <DropShadowEffect
         x:Key="shadow.error.s"
         BlurRadius="4"
-        Direction="270"
+        Direction="0"
         Opacity=" 0.4"
         ShadowDepth="0"
         Color="#F3465B" />

+ 26 - 7
PDF Office/Themes/Generic.xaml

@@ -45,6 +45,7 @@
         <Setter Property="Background" Value="{StaticResource color.field.bg.def}" />
         <Setter Property="BorderBrush" Value="{StaticResource color.field.border.norm}" />
         <Setter Property="Foreground" Value="Black" />
+        <Setter Property="VerticalContentAlignment" Value="Center" />
         <Setter Property="BorderThickness" Value="1" />
         <Setter Property="FocusVisualStyle" Value="{x:Null}" />
         <Setter Property="Template">
@@ -53,7 +54,7 @@
                     <Border
                         x:Name="border"
                         Width="{TemplateBinding Width}"
-                        Height="{TemplateBinding Height}"
+                        Height="32"
                         Background="{TemplateBinding Background}"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderThickness="{TemplateBinding BorderThickness}"
@@ -63,6 +64,7 @@
                             <TextBlock
                                 x:Name="placeholder"
                                 Margin="5,0,0,0"
+                                Padding="{TemplateBinding Padding}"
                                 FontSize="{TemplateBinding FontSize}"
                                 Foreground="{TemplateBinding PlaceholderForeground}"
                                 Text="{TemplateBinding PlaceholderText}"
@@ -70,8 +72,7 @@
 
                             <ScrollViewer
                                 x:Name="PART_ContentHost"
-                                Margin="0,0,25,0"
-                                Padding="8,1,0,0"
+                                Margin="8,0,25,0"
                                 Focusable="false"
                                 Foreground="{TemplateBinding Foreground}"
                                 HorizontalScrollBarVisibility="Hidden"
@@ -95,7 +96,6 @@
                                     Stretch="Uniform" />
                             </Button>
                         </Grid>
-
                     </Border>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsEnabled" Value="false">
@@ -104,11 +104,30 @@
                         <Trigger Property="Text" Value="{x:Null}">
                             <Setter TargetName="placeholder" Property="Visibility" Value="Visible" />
                         </Trigger>
-                        <Trigger Property="Text" Value="">
-                            <Setter TargetName="placeholder" Property="Visibility" Value="Visible" />
-                        </Trigger>
                         <Trigger Property="IsMouseOver" Value="True">
                             <Setter TargetName="PART_BtnClear" Property="Visibility" Value="Visible" />
+                            <Setter Property="BorderBrush" Value="{StaticResource color.field.border.hov}" />
+                        </Trigger>
+                        <Trigger Property="IsFocused" Value="True">
+                            <Setter TargetName="PART_BtnClear" Property="Visibility" Value="Visible" />
+                            <Setter Property="BorderBrush" Value="{StaticResource color.field.border.focus}" />
+                            <Setter TargetName="border" Property="Effect" Value="{StaticResource shadow.blue-0-4}" />
+                        </Trigger>
+                        <MultiTrigger>
+                            <MultiTrigger.Conditions>
+                                <Condition Property="IsFocused" Value="True" />
+                                <Condition Property="IsError" Value="True" />
+                            </MultiTrigger.Conditions>
+                            <MultiTrigger.Setters>
+                                <Setter TargetName="border" Property="Effect" Value="{StaticResource shadow.error.s}" />
+                            </MultiTrigger.Setters>
+                        </MultiTrigger>
+                        <Trigger Property="IsError" Value="True">
+                            <Setter Property="BorderBrush" Value="{StaticResource color.sys.border.error}" />
+                        </Trigger>
+                        <Trigger Property="Text" Value="">
+                            <Setter TargetName="placeholder" Property="Visibility" Value="Visible" />
+                            <Setter TargetName="PART_BtnClear" Property="Visibility" Value="Collapsed" />
                         </Trigger>
                         <MultiTrigger>
                             <MultiTrigger.Conditions>