ValidateTextBoxStyle.xaml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:MyControls="clr-namespace:CustomUI">
  4. <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
  5. <PathGeometry x:Key="Icon_IsRequired" Figures="M160.53116 582.580498l304.122509-51.851948L248.997004 310.312488l-1.393743 4.2897c-9.969049-6.334265-20.888749-11.528568-32.640398-15.346523-75.184353-24.429389-155.937538 16.715707-180.366927 91.901083s16.715707 155.937538 91.901083 180.366927c11.751648 3.817955 23.639396 6.034437 35.426861 6.769171L160.53116 582.580498 160.53116 582.580498zM209.606879 725.041094c-9.104355 7.523347-17.418718 16.303314-24.682146 26.299993-46.466288 63.955614-32.289404 153.47137 31.668257 199.938682 63.955614 46.466288 153.47137 32.289404 199.938682-31.667234 7.263427-9.996678 13.044084-20.618597 17.384949-31.601742l3.648087 2.650363 44.663222-305.259402L205.958792 722.390731 209.606879 725.041094 209.606879 725.041094zM812.525588 725.041094l3.648087-2.650363L539.655873 585.582879l44.912909 305.0793 3.648087-2.650363c4.341888 10.984169 10.122545 21.60404 17.385972 31.601742 46.466288 63.955614 135.983067 78.134545 199.938682 31.667234 63.956637-46.466288 78.134545-135.982044 31.668257-199.938682C829.944306 741.345432 821.62892 732.564441 812.525588 725.041094L812.525588 725.041094zM987.535507 391.155724c-24.429389-75.184353-105.182574-116.330472-180.366927-91.901083-11.751648 3.817955-22.672372 9.012258-32.640398 15.346523l-1.393743-4.2897L557.574988 531.019169l304.027341 51.560306-1.393743-4.2897c11.787464-0.735757 23.676236-2.951215 35.426861-6.769171C970.820823 547.093263 1011.965919 466.340077 987.535507 391.155724L987.535507 391.155724zM649.697105 223.903489c2.943029-11.437493 4.50971-23.428595 4.50971-35.785018 0-79.054497-64.085574-143.140071-143.141094-143.140071s-143.140071 64.085574-143.140071 143.140071c0 12.356422 1.566682 24.347524 4.50971 35.785018l-4.50971 0 143.293567 273.213545 142.986575-273.213545L649.697105 223.903489z" />
  6. <SolidColorBrush x:Key="TextBox.Static.BorderBrush">#9FA5AE</SolidColorBrush>
  7. <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA" />
  8. <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5" />
  9. <Style TargetType="{x:Type MyControls:ValidateTextBox}">
  10. <Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.BorderBrush}" />
  11. <Setter Property="Background" Value="White" />
  12. <Setter Property="BorderThickness" Value="1" />
  13. <Setter Property="FocusVisualStyle" Value="{x:Null}" />
  14. <Setter Property="VerticalContentAlignment" Value="Center" />
  15. <Setter Property="Template">
  16. <Setter.Value>
  17. <ControlTemplate TargetType="{x:Type MyControls:ValidateTextBox}">
  18. <Grid>
  19. <Grid.ColumnDefinitions>
  20. <ColumnDefinition Width="*" />
  21. <ColumnDefinition Width="auto" />
  22. </Grid.ColumnDefinitions>
  23. <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}"
  24. BorderThickness="{TemplateBinding BorderThickness}"
  25. Background="{TemplateBinding Background}"
  26. UseLayoutRounding="True" SnapsToDevicePixels="True">
  27. <ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="false"
  28. HorizontalScrollBarVisibility="Hidden"
  29. VerticalScrollBarVisibility="Hidden" />
  30. </Border>
  31. <Border x:Name="red_border" Width="Auto" Margin="0" HorizontalAlignment="Stretch"
  32. BorderBrush="#FFDB000C" BorderThickness="1" CornerRadius="1" Visibility="Collapsed"
  33. UseLayoutRounding="True" SnapsToDevicePixels="True">
  34. <Grid Width="12" Height="12" Margin="1,-4,-4,0" HorizontalAlignment="Right"
  35. VerticalAlignment="Top" Background="Transparent">
  36. <Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C" />
  37. <Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff" />
  38. </Grid>
  39. </Border>
  40. <Path x:Name="RequireLabel" Grid.Column="1" Data="{StaticResource Icon_IsRequired}"
  41. Stretch="Uniform" Fill="Red" Width="10"
  42. VerticalAlignment="Center" Margin="5,0,0,0"
  43. Visibility="{Binding IsRequired, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
  44. <!--<TextBlock x:Name="RequireLabel" Text="*" Grid.Column="1" Foreground="Red"
  45. VerticalAlignment="Center" Margin="5,0,0,0"
  46. Visibility="{Binding IsRequired, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>-->
  47. <Popup x:Name="PART_ErrorPopup" Grid.Column="1"
  48. AllowsTransparency="True" IsOpen="False" Placement="Right"
  49. PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
  50. StaysOpen="True">
  51. <Grid Margin="2,10,10,10" x:Name="border1_Copy" Opacity="0" RenderTransformOrigin="0.5,0.5">
  52. <Grid.RenderTransform>
  53. <TransformGroup>
  54. <ScaleTransform />
  55. <SkewTransform />
  56. <RotateTransform />
  57. <TranslateTransform X="10" />
  58. </TransformGroup>
  59. </Grid.RenderTransform>
  60. <Border Background="#FFFFFF" SnapsToDevicePixels="True" UseLayoutRounding="True">
  61. <Border.Effect>
  62. <DropShadowEffect BlurRadius="13" Opacity="0.4" ShadowDepth="1" Color="Brown" />
  63. </Border.Effect>
  64. </Border>
  65. <Border Width="Auto" Height="Auto" Margin="-3" Padding="5,5"
  66. HorizontalAlignment="Stretch" Background="Red" BorderThickness="1" CornerRadius="2"
  67. SnapsToDevicePixels="True" UseLayoutRounding="True">
  68. <TextBlock x:Name="PART_ErrorContent" HorizontalAlignment="Center"
  69. VerticalAlignment="Center" Foreground="White"
  70. TextWrapping="NoWrap" FontSize="12" FontFamily="微软雅黑"/>
  71. </Border>
  72. </Grid>
  73. </Popup>
  74. <VisualStateManager.VisualStateGroups>
  75. <VisualStateGroup x:Name="CommonStates">
  76. <VisualState x:Name="InvalidFocused">
  77. <Storyboard>
  78. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="red_border" Storyboard.TargetProperty="(UIElement.Visibility)">
  79. <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
  80. </ObjectAnimationUsingKeyFrames>
  81. <DoubleAnimationUsingKeyFrames Storyboard.TargetName="border1_Copy" Storyboard.TargetProperty="(UIElement.Opacity)">
  82. <SplineDoubleKeyFrame KeyTime="0" Value="1" />
  83. <SplineDoubleKeyFrame KeyTime="0:0:0.1" Value="1" />
  84. <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="1" />
  85. </DoubleAnimationUsingKeyFrames>
  86. <DoubleAnimationUsingKeyFrames Storyboard.TargetName="border1_Copy" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
  87. <EasingDoubleKeyFrame KeyTime="0" Value="0" />
  88. <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="5">
  89. <EasingDoubleKeyFrame.EasingFunction>
  90. <QuarticEase EasingMode="EaseInOut" />
  91. </EasingDoubleKeyFrame.EasingFunction>
  92. </EasingDoubleKeyFrame>
  93. <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
  94. <EasingDoubleKeyFrame.EasingFunction>
  95. <QuarticEase EasingMode="EaseInOut" />
  96. </EasingDoubleKeyFrame.EasingFunction>
  97. </EasingDoubleKeyFrame>
  98. </DoubleAnimationUsingKeyFrames>
  99. <BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_ErrorPopup" Storyboard.TargetProperty="(Popup.IsOpen)">
  100. <DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
  101. </BooleanAnimationUsingKeyFrames>
  102. </Storyboard>
  103. </VisualState>
  104. <VisualState x:Name="InvalidUnfocused">
  105. <Storyboard>
  106. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="red_border" Storyboard.TargetProperty="(UIElement.Visibility)">
  107. <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
  108. </ObjectAnimationUsingKeyFrames>
  109. <BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_ErrorPopup" Storyboard.TargetProperty="(Popup.IsOpen)">
  110. <DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
  111. </BooleanAnimationUsingKeyFrames>
  112. </Storyboard>
  113. </VisualState>
  114. <!--验证通过,并失去焦点-->
  115. <VisualState x:Name="ValidUnfocused">
  116. <Storyboard>
  117. <BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_ErrorPopup" Storyboard.TargetProperty="(Popup.IsOpen)">
  118. <DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
  119. </BooleanAnimationUsingKeyFrames>
  120. </Storyboard>
  121. </VisualState>
  122. </VisualStateGroup>
  123. </VisualStateManager.VisualStateGroups>
  124. </Grid>
  125. <ControlTemplate.Triggers>
  126. <Trigger Property="IsEnabled" Value="false">
  127. <Setter TargetName="border" Property="BorderThickness" Value="0" />
  128. <Setter TargetName="border" Property="Background" Value="Transparent" />
  129. <Setter Property="Foreground" Value="#888888" />
  130. <Setter TargetName="RequireLabel" Property="Visibility" Value="Collapsed" />
  131. <Setter TargetName="PART_ErrorPopup" Property="IsOpen" Value="False" />
  132. <Setter TargetName="red_border" Property="Visibility" Value="Collapsed" />
  133. </Trigger>
  134. <Trigger Property="IsMouseOver" Value="true">
  135. <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource TextBox.MouseOver.Border}" />
  136. </Trigger>
  137. <Trigger Property="IsKeyboardFocused" Value="true">
  138. <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource TextBox.Focus.Border}" />
  139. <Setter TargetName="border" Property="Background" Value="#FFFFFF" />
  140. </Trigger>
  141. </ControlTemplate.Triggers>
  142. </ControlTemplate>
  143. </Setter.Value>
  144. </Setter>
  145. </Style>
  146. </ResourceDictionary>