Separated out the validation behavior from the validation effect.
This commit is contained in:
		
							parent
							
								
									8c04a0d249
								
							
						
					
					
						commit
						2ecc1e643b
					
				| @ -3,7 +3,7 @@ | |||||||
|              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"   |              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"   | ||||||
|              xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light" |              xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light" | ||||||
|              xmlns:converters="clr-namespace:eShopOnContainers.Core.Converters;assembly=eShopOnContainers.Core" |              xmlns:converters="clr-namespace:eShopOnContainers.Core.Converters;assembly=eShopOnContainers.Core" | ||||||
|              xmlns:effects="clr-namespace:eShopOnContainers.Core.Effects;assembly=eShopOnContainers.Core" |              xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core" | ||||||
|              x:Class="eShopOnContainers.App"> |              x:Class="eShopOnContainers.App"> | ||||||
|     <Application.Resources> |     <Application.Resources> | ||||||
|         <ResourceDictionary MergedWith="light:LightThemeResources"> |         <ResourceDictionary MergedWith="light:LightThemeResources"> | ||||||
| @ -135,9 +135,9 @@ | |||||||
|                         Value="Bold" /> |                         Value="Bold" /> | ||||||
|                 <Setter Property="Opacity" |                 <Setter Property="Opacity" | ||||||
|                         Value="0.6" /> |                         Value="0.6" /> | ||||||
|                 <Setter Property="effects:LineColorEffect.ApplyLineColor" |                 <Setter Property="behaviors:LineColorBehavior.ApplyLineColor" | ||||||
|                         Value="True" /> |                         Value="True" /> | ||||||
|                 <Setter Property="effects:LineColorEffect.LineColor" |                 <Setter Property="behaviors:LineColorBehavior.LineColor" | ||||||
|                         Value="{StaticResource BlackColor}" /> |                         Value="{StaticResource BlackColor}" /> | ||||||
|                 <Style.Triggers> |                 <Style.Triggers> | ||||||
|                     <Trigger TargetType="Entry" |                     <Trigger TargetType="Entry" | ||||||
| @ -166,16 +166,16 @@ | |||||||
|                         Value="Transparent" /> |                         Value="Transparent" /> | ||||||
|                 <Setter Property="Opacity" |                 <Setter Property="Opacity" | ||||||
|                         Value="0.6" /> |                         Value="0.6" /> | ||||||
|                 <Setter Property="effects:LineColorEffect.ApplyLineColor" |                 <Setter Property="behaviors:LineColorBehavior.ApplyLineColor" | ||||||
|                         Value="True" /> |                         Value="True" /> | ||||||
|                 <Setter Property="effects:LineColorEffect.LineColor" |                 <Setter Property="behaviors:LineColorBehavior.LineColor" | ||||||
|                         Value="Gray" /> |                         Value="Gray" /> | ||||||
|                 <Style.Triggers> |                 <Style.Triggers> | ||||||
|                     <Trigger TargetType="Entry" |                     <Trigger TargetType="Entry" | ||||||
|                        Property="IsFocused" |                        Property="IsFocused" | ||||||
|                        Value="True"> |                        Value="True"> | ||||||
|                         <Setter Property="Opacity" Value="1" /> |                         <Setter Property="Opacity" Value="1" /> | ||||||
|                         <Setter Property="effects:LineColorEffect.LineColor"                         |                         <Setter Property="behaviors:LineColorBehavior.LineColor"                         | ||||||
|                                 Value="{StaticResource GreenColor}" /> |                                 Value="{StaticResource GreenColor}" /> | ||||||
|                     </Trigger> |                     </Trigger> | ||||||
|                 </Style.Triggers> |                 </Style.Triggers> | ||||||
|  | |||||||
| @ -1,14 +1,18 @@ | |||||||
| using System.Linq; | using System.Linq; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
|  | using eShopOnContainers.Core.Effects; | ||||||
| 
 | 
 | ||||||
| namespace eShopOnContainers.Core.Effects | namespace eShopOnContainers.Core.Behaviors | ||||||
| { | { | ||||||
|     public static class LineColorEffect |     public static class LineColorBehavior | ||||||
|     { |     { | ||||||
|         public static readonly BindableProperty ApplyLineColorProperty = |         public static readonly BindableProperty ApplyLineColorProperty = | ||||||
|             BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorEffect), false,  |             BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorBehavior), false,  | ||||||
|                 propertyChanged: OnApplyLineColorChanged); |                 propertyChanged: OnApplyLineColorChanged); | ||||||
| 
 | 
 | ||||||
|  | 		public static readonly BindableProperty LineColorProperty = | ||||||
|  | 			BindableProperty.CreateAttached("LineColor", typeof(Color), typeof(LineColorBehavior), Color.Default); | ||||||
|  | 
 | ||||||
|         public static bool GetApplyLineColor(BindableObject view) |         public static bool GetApplyLineColor(BindableObject view) | ||||||
|         { |         { | ||||||
|             return (bool)view.GetValue(ApplyLineColorProperty); |             return (bool)view.GetValue(ApplyLineColorProperty); | ||||||
| @ -19,6 +23,16 @@ namespace eShopOnContainers.Core.Effects | |||||||
|             view.SetValue(ApplyLineColorProperty, value); |             view.SetValue(ApplyLineColorProperty, value); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | 		public static Color GetLineColor(BindableObject view) | ||||||
|  | 		{ | ||||||
|  | 			return (Color)view.GetValue(LineColorProperty); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		public static void SetLineColor(BindableObject view, Color value) | ||||||
|  | 		{ | ||||||
|  | 			view.SetValue(LineColorProperty, value); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|         private static void OnApplyLineColorChanged(BindableObject bindable, object oldValue, object newValue) |         private static void OnApplyLineColorChanged(BindableObject bindable, object oldValue, object newValue) | ||||||
|         { |         { | ||||||
|             var view = bindable as View; |             var view = bindable as View; | ||||||
| @ -43,25 +57,5 @@ namespace eShopOnContainers.Core.Effects | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         public static readonly BindableProperty LineColorProperty = |  | ||||||
|             BindableProperty.CreateAttached("LineColor", typeof(Color), typeof(LineColorEffect), Color.Default); |  | ||||||
| 
 |  | ||||||
|         public static Color GetLineColor(BindableObject view) |  | ||||||
|         { |  | ||||||
|             return (Color)view.GetValue(LineColorProperty); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         public static void SetLineColor(BindableObject view, Color value) |  | ||||||
|         { |  | ||||||
|             view.SetValue(LineColorProperty, value); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         class EntryLineColorEffect : RoutingEffect |  | ||||||
|         { |  | ||||||
|             public EntryLineColorEffect() : base("eShopOnContainers.EntryLineColorEffect") |  | ||||||
|             { |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | using Xamarin.Forms; | ||||||
|  | 
 | ||||||
|  | namespace eShopOnContainers.Core.Effects | ||||||
|  | { | ||||||
|  | 	public class EntryLineColorEffect : RoutingEffect | ||||||
|  | 	{ | ||||||
|  | 		public EntryLineColorEffect() : base("eShopOnContainers.EntryLineColorEffect") | ||||||
|  | 		{ | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -6,7 +6,6 @@ | |||||||
|              xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core" |              xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core" | ||||||
|              xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core" |              xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core" | ||||||
|              xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core" |              xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core" | ||||||
| 			 xmlns:effects="clr-namespace:eShopOnContainers.Core.Effects;assembly=eShopOnContainers.Core" |  | ||||||
| 			 viewModelBase:ViewModelLocator.AutoWireViewModel="true"> | 			 viewModelBase:ViewModelLocator.AutoWireViewModel="true"> | ||||||
|     <ContentPage.Title> |     <ContentPage.Title> | ||||||
|         <OnPlatform |         <OnPlatform | ||||||
| @ -196,7 +195,7 @@ | |||||||
| 							TargetType="Entry" | 							TargetType="Entry" | ||||||
| 							Binding="{Binding UserName.IsValid}" | 							Binding="{Binding UserName.IsValid}" | ||||||
| 							Value="False"> | 							Value="False"> | ||||||
| 							<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" /> | 							<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" /> | ||||||
| 						</DataTrigger> | 						</DataTrigger> | ||||||
| 					</Entry.Triggers> | 					</Entry.Triggers> | ||||||
|                 </Entry> |                 </Entry> | ||||||
| @ -225,7 +224,7 @@ | |||||||
| 							TargetType="Entry" | 							TargetType="Entry" | ||||||
| 							Binding="{Binding Password.IsValid}" | 							Binding="{Binding Password.IsValid}" | ||||||
| 							Value="False"> | 							Value="False"> | ||||||
| 							<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" /> | 							<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" /> | ||||||
| 						</DataTrigger> | 						</DataTrigger> | ||||||
| 					</Entry.Triggers> | 					</Entry.Triggers> | ||||||
|                 </Entry> |                 </Entry> | ||||||
|  | |||||||
| @ -58,7 +58,6 @@ | |||||||
|     <Compile Include="Converters\ItemsToHeightConverter.cs" /> |     <Compile Include="Converters\ItemsToHeightConverter.cs" /> | ||||||
|     <Compile Include="Converters\ItemTappedEventArgsConverter.cs" /> |     <Compile Include="Converters\ItemTappedEventArgsConverter.cs" /> | ||||||
|     <Compile Include="Converters\ToUpperConverter.cs" /> |     <Compile Include="Converters\ToUpperConverter.cs" /> | ||||||
|     <Compile Include="Effects\LineColorEffect.cs" /> |  | ||||||
|     <Compile Include="Exceptions\ServiceAuthenticationException.cs" /> |     <Compile Include="Exceptions\ServiceAuthenticationException.cs" /> | ||||||
|     <Compile Include="Extensions\ObservableExtension.cs" /> |     <Compile Include="Extensions\ObservableExtension.cs" /> | ||||||
|     <Compile Include="GlobalSettings.cs" /> |     <Compile Include="GlobalSettings.cs" /> | ||||||
| @ -165,6 +164,8 @@ | |||||||
|     </Compile> |     </Compile> | ||||||
|     <Compile Include="Converters\WebNavigatingEventArgsConverter.cs" /> |     <Compile Include="Converters\WebNavigatingEventArgsConverter.cs" /> | ||||||
|     <Compile Include="Converters\FirstValidationErrorConverter.cs" /> |     <Compile Include="Converters\FirstValidationErrorConverter.cs" /> | ||||||
|  |     <Compile Include="Effects\EntryLineColorEffect.cs" /> | ||||||
|  |     <Compile Include="Behaviors\LineColorBehavior.cs" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <None Include="app.config" /> |     <None Include="app.config" /> | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ using eShopOnContainers.Droid.Effects; | |||||||
| using Xamarin.Forms.Platform.Android; | using Xamarin.Forms.Platform.Android; | ||||||
| using System; | using System; | ||||||
| using Android.Widget; | using Android.Widget; | ||||||
| using eShopOnContainers.Core.Effects; | using eShopOnContainers.Core.Behaviors; | ||||||
| using System.ComponentModel; | using System.ComponentModel; | ||||||
| using System.Diagnostics; | using System.Diagnostics; | ||||||
| 
 | 
 | ||||||
| @ -34,7 +34,7 @@ namespace eShopOnContainers.Droid.Effects | |||||||
| 
 | 
 | ||||||
|         protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) |         protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) | ||||||
|         { |         { | ||||||
|             if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName) |             if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName) | ||||||
|             { |             { | ||||||
|                 UpdateLineColor(); |                 UpdateLineColor(); | ||||||
|             } |             } | ||||||
| @ -46,7 +46,7 @@ namespace eShopOnContainers.Droid.Effects | |||||||
|             { |             { | ||||||
|                 if (control != null) |                 if (control != null) | ||||||
|                 { |                 { | ||||||
|                     control.Background.SetColorFilter(LineColorEffect.GetLineColor(Element).ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop); |                     control.Background.SetColorFilter(LineColorBehavior.GetLineColor(Element).ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ using Xamarin.Forms; | |||||||
| using Xamarin.Forms.Platform.UWP; | using Xamarin.Forms.Platform.UWP; | ||||||
| using Windows.UI.Xaml.Controls; | using Windows.UI.Xaml.Controls; | ||||||
| using eShopOnContainers.Windows.Effects; | using eShopOnContainers.Windows.Effects; | ||||||
| using eShopOnContainers.Core.Effects; | using eShopOnContainers.Core.Behaviors; | ||||||
| 
 | 
 | ||||||
| [assembly: ResolutionGroupName("eShopOnContainers")] | [assembly: ResolutionGroupName("eShopOnContainers")] | ||||||
| [assembly: ExportEffect(typeof(EntryLineColorEffect), "EntryLineColorEffect")] | [assembly: ExportEffect(typeof(EntryLineColorEffect), "EntryLineColorEffect")] | ||||||
| @ -38,7 +38,7 @@ namespace eShopOnContainers.Windows.Effects | |||||||
| 
 | 
 | ||||||
|         protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) |         protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) | ||||||
|         { |         { | ||||||
|             if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName) |             if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName) | ||||||
|             { |             { | ||||||
|                 UpdateLineColor(); |                 UpdateLineColor(); | ||||||
|             } |             } | ||||||
| @ -49,7 +49,7 @@ namespace eShopOnContainers.Windows.Effects | |||||||
|             if (control != null) |             if (control != null) | ||||||
|             { |             { | ||||||
|                 control.BorderThickness = new Xaml.Thickness(0, 0, 0, 1); |                 control.BorderThickness = new Xaml.Thickness(0, 0, 0, 1); | ||||||
|                 var lineColor = XamarinFormColorToWindowsColor(LineColorEffect.GetLineColor(Element)); |                 var lineColor = XamarinFormColorToWindowsColor(LineColorBehavior.GetLineColor(Element)); | ||||||
|                 control.BorderBrush = new Media.SolidColorBrush(lineColor); |                 control.BorderBrush = new Media.SolidColorBrush(lineColor); | ||||||
| 
 | 
 | ||||||
|                 var style = Xaml.Application.Current.Resources["FormTextBoxStyle"] as Xaml.Style; |                 var style = Xaml.Application.Current.Resources["FormTextBoxStyle"] as Xaml.Style; | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| using CoreAnimation; | using CoreAnimation; | ||||||
| using CoreGraphics; | using CoreGraphics; | ||||||
| using eShopOnContainers.Core.Effects; | using eShopOnContainers.Core.Behaviors; | ||||||
| using eShopOnContainers.iOS.Effects; | using eShopOnContainers.iOS.Effects; | ||||||
| using System; | using System; | ||||||
| using System.ComponentModel; | using System.ComponentModel; | ||||||
| @ -39,7 +39,7 @@ namespace eShopOnContainers.iOS.Effects | |||||||
|         { |         { | ||||||
|             base.OnElementPropertyChanged(args); |             base.OnElementPropertyChanged(args); | ||||||
| 
 | 
 | ||||||
|             if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName || |             if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName || | ||||||
|                 args.PropertyName == "Height") |                 args.PropertyName == "Height") | ||||||
|             { |             { | ||||||
|                 Initialize(); |                 Initialize(); | ||||||
| @ -71,7 +71,7 @@ namespace eShopOnContainers.iOS.Effects | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             lineLayer.Frame = new CGRect(0f, Control.Frame.Height - 1f, Control.Bounds.Width, 1f); |             lineLayer.Frame = new CGRect(0f, Control.Frame.Height - 1f, Control.Bounds.Width, 1f); | ||||||
|             lineLayer.BorderColor = LineColorEffect.GetLineColor(Element).ToCGColor(); |             lineLayer.BorderColor = LineColorBehavior.GetLineColor(Element).ToCGColor(); | ||||||
|             control.TintColor = control.TextColor; |             control.TintColor = control.TextColor; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user