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:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light"
|
||||
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">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary MergedWith="light:LightThemeResources">
|
||||
@ -135,9 +135,9 @@
|
||||
Value="Bold" />
|
||||
<Setter Property="Opacity"
|
||||
Value="0.6" />
|
||||
<Setter Property="effects:LineColorEffect.ApplyLineColor"
|
||||
<Setter Property="behaviors:LineColorBehavior.ApplyLineColor"
|
||||
Value="True" />
|
||||
<Setter Property="effects:LineColorEffect.LineColor"
|
||||
<Setter Property="behaviors:LineColorBehavior.LineColor"
|
||||
Value="{StaticResource BlackColor}" />
|
||||
<Style.Triggers>
|
||||
<Trigger TargetType="Entry"
|
||||
@ -166,16 +166,16 @@
|
||||
Value="Transparent" />
|
||||
<Setter Property="Opacity"
|
||||
Value="0.6" />
|
||||
<Setter Property="effects:LineColorEffect.ApplyLineColor"
|
||||
<Setter Property="behaviors:LineColorBehavior.ApplyLineColor"
|
||||
Value="True" />
|
||||
<Setter Property="effects:LineColorEffect.LineColor"
|
||||
<Setter Property="behaviors:LineColorBehavior.LineColor"
|
||||
Value="Gray" />
|
||||
<Style.Triggers>
|
||||
<Trigger TargetType="Entry"
|
||||
Property="IsFocused"
|
||||
Value="True">
|
||||
<Setter Property="Opacity" Value="1" />
|
||||
<Setter Property="effects:LineColorEffect.LineColor"
|
||||
<Setter Property="behaviors:LineColorBehavior.LineColor"
|
||||
Value="{StaticResource GreenColor}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
|
@ -1,14 +1,18 @@
|
||||
using System.Linq;
|
||||
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 =
|
||||
BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorEffect), false,
|
||||
BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorBehavior), false,
|
||||
propertyChanged: OnApplyLineColorChanged);
|
||||
|
||||
public static readonly BindableProperty LineColorProperty =
|
||||
BindableProperty.CreateAttached("LineColor", typeof(Color), typeof(LineColorBehavior), Color.Default);
|
||||
|
||||
public static bool GetApplyLineColor(BindableObject view)
|
||||
{
|
||||
return (bool)view.GetValue(ApplyLineColorProperty);
|
||||
@ -19,6 +23,16 @@ namespace eShopOnContainers.Core.Effects
|
||||
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)
|
||||
{
|
||||
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:triggers="clr-namespace:eShopOnContainers.Core.Triggers;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">
|
||||
<ContentPage.Title>
|
||||
<OnPlatform
|
||||
@ -196,7 +195,7 @@
|
||||
TargetType="Entry"
|
||||
Binding="{Binding UserName.IsValid}"
|
||||
Value="False">
|
||||
<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" />
|
||||
<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" />
|
||||
</DataTrigger>
|
||||
</Entry.Triggers>
|
||||
</Entry>
|
||||
@ -225,7 +224,7 @@
|
||||
TargetType="Entry"
|
||||
Binding="{Binding Password.IsValid}"
|
||||
Value="False">
|
||||
<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" />
|
||||
<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" />
|
||||
</DataTrigger>
|
||||
</Entry.Triggers>
|
||||
</Entry>
|
||||
|
@ -58,7 +58,6 @@
|
||||
<Compile Include="Converters\ItemsToHeightConverter.cs" />
|
||||
<Compile Include="Converters\ItemTappedEventArgsConverter.cs" />
|
||||
<Compile Include="Converters\ToUpperConverter.cs" />
|
||||
<Compile Include="Effects\LineColorEffect.cs" />
|
||||
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
|
||||
<Compile Include="Extensions\ObservableExtension.cs" />
|
||||
<Compile Include="GlobalSettings.cs" />
|
||||
@ -165,6 +164,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Converters\WebNavigatingEventArgsConverter.cs" />
|
||||
<Compile Include="Converters\FirstValidationErrorConverter.cs" />
|
||||
<Compile Include="Effects\EntryLineColorEffect.cs" />
|
||||
<Compile Include="Behaviors\LineColorBehavior.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
@ -3,7 +3,7 @@ using eShopOnContainers.Droid.Effects;
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using System;
|
||||
using Android.Widget;
|
||||
using eShopOnContainers.Core.Effects;
|
||||
using eShopOnContainers.Core.Behaviors;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
@ -34,7 +34,7 @@ namespace eShopOnContainers.Droid.Effects
|
||||
|
||||
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
|
||||
{
|
||||
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName)
|
||||
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName)
|
||||
{
|
||||
UpdateLineColor();
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace eShopOnContainers.Droid.Effects
|
||||
{
|
||||
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)
|
||||
|
@ -8,7 +8,7 @@ using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.UWP;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using eShopOnContainers.Windows.Effects;
|
||||
using eShopOnContainers.Core.Effects;
|
||||
using eShopOnContainers.Core.Behaviors;
|
||||
|
||||
[assembly: ResolutionGroupName("eShopOnContainers")]
|
||||
[assembly: ExportEffect(typeof(EntryLineColorEffect), "EntryLineColorEffect")]
|
||||
@ -38,7 +38,7 @@ namespace eShopOnContainers.Windows.Effects
|
||||
|
||||
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
|
||||
{
|
||||
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName)
|
||||
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName)
|
||||
{
|
||||
UpdateLineColor();
|
||||
}
|
||||
@ -49,7 +49,7 @@ namespace eShopOnContainers.Windows.Effects
|
||||
if (control != null)
|
||||
{
|
||||
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);
|
||||
|
||||
var style = Xaml.Application.Current.Resources["FormTextBoxStyle"] as Xaml.Style;
|
||||
|
@ -1,6 +1,6 @@
|
||||
using CoreAnimation;
|
||||
using CoreGraphics;
|
||||
using eShopOnContainers.Core.Effects;
|
||||
using eShopOnContainers.Core.Behaviors;
|
||||
using eShopOnContainers.iOS.Effects;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
@ -39,7 +39,7 @@ namespace eShopOnContainers.iOS.Effects
|
||||
{
|
||||
base.OnElementPropertyChanged(args);
|
||||
|
||||
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName ||
|
||||
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName ||
|
||||
args.PropertyName == "Height")
|
||||
{
|
||||
Initialize();
|
||||
@ -71,7 +71,7 @@ namespace eShopOnContainers.iOS.Effects
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user