Skip to content

Commit 2ecc1e6

Browse files
David BritchDavid Britch
authored andcommitted
Separated out the validation behavior from the validation effect.
1 parent 8c04a0d commit 2ecc1e6

8 files changed

Lines changed: 47 additions & 42 deletions

File tree

src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light"
55
xmlns:converters="clr-namespace:eShopOnContainers.Core.Converters;assembly=eShopOnContainers.Core"
6-
xmlns:effects="clr-namespace:eShopOnContainers.Core.Effects;assembly=eShopOnContainers.Core"
6+
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
77
x:Class="eShopOnContainers.App">
88
<Application.Resources>
99
<ResourceDictionary MergedWith="light:LightThemeResources">
@@ -135,9 +135,9 @@
135135
Value="Bold" />
136136
<Setter Property="Opacity"
137137
Value="0.6" />
138-
<Setter Property="effects:LineColorEffect.ApplyLineColor"
138+
<Setter Property="behaviors:LineColorBehavior.ApplyLineColor"
139139
Value="True" />
140-
<Setter Property="effects:LineColorEffect.LineColor"
140+
<Setter Property="behaviors:LineColorBehavior.LineColor"
141141
Value="{StaticResource BlackColor}" />
142142
<Style.Triggers>
143143
<Trigger TargetType="Entry"
@@ -166,16 +166,16 @@
166166
Value="Transparent" />
167167
<Setter Property="Opacity"
168168
Value="0.6" />
169-
<Setter Property="effects:LineColorEffect.ApplyLineColor"
169+
<Setter Property="behaviors:LineColorBehavior.ApplyLineColor"
170170
Value="True" />
171-
<Setter Property="effects:LineColorEffect.LineColor"
171+
<Setter Property="behaviors:LineColorBehavior.LineColor"
172172
Value="Gray" />
173173
<Style.Triggers>
174174
<Trigger TargetType="Entry"
175175
Property="IsFocused"
176176
Value="True">
177177
<Setter Property="Opacity" Value="1" />
178-
<Setter Property="effects:LineColorEffect.LineColor"
178+
<Setter Property="behaviors:LineColorBehavior.LineColor"
179179
Value="{StaticResource GreenColor}" />
180180
</Trigger>
181181
</Style.Triggers>

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Effects/LineColorEffect.cs renamed to src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/LineColorBehavior.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
using System.Linq;
22
using Xamarin.Forms;
3+
using eShopOnContainers.Core.Effects;
34

4-
namespace eShopOnContainers.Core.Effects
5+
namespace eShopOnContainers.Core.Behaviors
56
{
6-
public static class LineColorEffect
7+
public static class LineColorBehavior
78
{
89
public static readonly BindableProperty ApplyLineColorProperty =
9-
BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorEffect), false,
10+
BindableProperty.CreateAttached("ApplyLineColor", typeof(bool), typeof(LineColorBehavior), false,
1011
propertyChanged: OnApplyLineColorChanged);
1112

13+
public static readonly BindableProperty LineColorProperty =
14+
BindableProperty.CreateAttached("LineColor", typeof(Color), typeof(LineColorBehavior), Color.Default);
15+
1216
public static bool GetApplyLineColor(BindableObject view)
1317
{
1418
return (bool)view.GetValue(ApplyLineColorProperty);
@@ -19,6 +23,16 @@ public static void SetApplyLineColor(BindableObject view, bool value)
1923
view.SetValue(ApplyLineColorProperty, value);
2024
}
2125

26+
public static Color GetLineColor(BindableObject view)
27+
{
28+
return (Color)view.GetValue(LineColorProperty);
29+
}
30+
31+
public static void SetLineColor(BindableObject view, Color value)
32+
{
33+
view.SetValue(LineColorProperty, value);
34+
}
35+
2236
private static void OnApplyLineColorChanged(BindableObject bindable, object oldValue, object newValue)
2337
{
2438
var view = bindable as View;
@@ -43,25 +57,5 @@ private static void OnApplyLineColorChanged(BindableObject bindable, object oldV
4357
}
4458
}
4559
}
46-
47-
public static readonly BindableProperty LineColorProperty =
48-
BindableProperty.CreateAttached("LineColor", typeof(Color), typeof(LineColorEffect), Color.Default);
49-
50-
public static Color GetLineColor(BindableObject view)
51-
{
52-
return (Color)view.GetValue(LineColorProperty);
53-
}
54-
55-
public static void SetLineColor(BindableObject view, Color value)
56-
{
57-
view.SetValue(LineColorProperty, value);
58-
}
59-
60-
class EntryLineColorEffect : RoutingEffect
61-
{
62-
public EntryLineColorEffect() : base("eShopOnContainers.EntryLineColorEffect")
63-
{
64-
}
65-
}
6660
}
6761
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Xamarin.Forms;
2+
3+
namespace eShopOnContainers.Core.Effects
4+
{
5+
public class EntryLineColorEffect : RoutingEffect
6+
{
7+
public EntryLineColorEffect() : base("eShopOnContainers.EntryLineColorEffect")
8+
{
9+
}
10+
}
11+
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/LoginView.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
77
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
88
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
9-
xmlns:effects="clr-namespace:eShopOnContainers.Core.Effects;assembly=eShopOnContainers.Core"
109
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
1110
<ContentPage.Title>
1211
<OnPlatform
@@ -196,7 +195,7 @@
196195
TargetType="Entry"
197196
Binding="{Binding UserName.IsValid}"
198197
Value="False">
199-
<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" />
198+
<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" />
200199
</DataTrigger>
201200
</Entry.Triggers>
202201
</Entry>
@@ -225,7 +224,7 @@
225224
TargetType="Entry"
226225
Binding="{Binding Password.IsValid}"
227226
Value="False">
228-
<Setter Property="effects:LineColorEffect.LineColor" Value="{StaticResource ErrorColor}" />
227+
<Setter Property="behaviors:LineColorBehavior.LineColor" Value="{StaticResource ErrorColor}" />
229228
</DataTrigger>
230229
</Entry.Triggers>
231230
</Entry>

src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
<Compile Include="Converters\ItemsToHeightConverter.cs" />
5959
<Compile Include="Converters\ItemTappedEventArgsConverter.cs" />
6060
<Compile Include="Converters\ToUpperConverter.cs" />
61-
<Compile Include="Effects\LineColorEffect.cs" />
6261
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
6362
<Compile Include="Extensions\ObservableExtension.cs" />
6463
<Compile Include="GlobalSettings.cs" />
@@ -165,6 +164,8 @@
165164
</Compile>
166165
<Compile Include="Converters\WebNavigatingEventArgsConverter.cs" />
167166
<Compile Include="Converters\FirstValidationErrorConverter.cs" />
167+
<Compile Include="Effects\EntryLineColorEffect.cs" />
168+
<Compile Include="Behaviors\LineColorBehavior.cs" />
168169
</ItemGroup>
169170
<ItemGroup>
170171
<None Include="app.config" />

src/Mobile/eShopOnContainers/eShopOnContainers.Droid/Effects/EntryLineColorEffect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Xamarin.Forms.Platform.Android;
44
using System;
55
using Android.Widget;
6-
using eShopOnContainers.Core.Effects;
6+
using eShopOnContainers.Core.Behaviors;
77
using System.ComponentModel;
88
using System.Diagnostics;
99

@@ -34,7 +34,7 @@ protected override void OnDetached()
3434

3535
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
3636
{
37-
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName)
37+
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName)
3838
{
3939
UpdateLineColor();
4040
}
@@ -46,7 +46,7 @@ private void UpdateLineColor()
4646
{
4747
if (control != null)
4848
{
49-
control.Background.SetColorFilter(LineColorEffect.GetLineColor(Element).ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop);
49+
control.Background.SetColorFilter(LineColorBehavior.GetLineColor(Element).ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop);
5050
}
5151
}
5252
catch (Exception ex)

src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Effects/EntryLineColorEffect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Xamarin.Forms.Platform.UWP;
99
using Windows.UI.Xaml.Controls;
1010
using eShopOnContainers.Windows.Effects;
11-
using eShopOnContainers.Core.Effects;
11+
using eShopOnContainers.Core.Behaviors;
1212

1313
[assembly: ResolutionGroupName("eShopOnContainers")]
1414
[assembly: ExportEffect(typeof(EntryLineColorEffect), "EntryLineColorEffect")]
@@ -38,7 +38,7 @@ protected override void OnDetached()
3838

3939
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
4040
{
41-
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName)
41+
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName)
4242
{
4343
UpdateLineColor();
4444
}
@@ -49,7 +49,7 @@ private void UpdateLineColor()
4949
if (control != null)
5050
{
5151
control.BorderThickness = new Xaml.Thickness(0, 0, 0, 1);
52-
var lineColor = XamarinFormColorToWindowsColor(LineColorEffect.GetLineColor(Element));
52+
var lineColor = XamarinFormColorToWindowsColor(LineColorBehavior.GetLineColor(Element));
5353
control.BorderBrush = new Media.SolidColorBrush(lineColor);
5454

5555
var style = Xaml.Application.Current.Resources["FormTextBoxStyle"] as Xaml.Style;

src/Mobile/eShopOnContainers/eShopOnContainers.iOS/Effects/EntryLineColorEffect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using CoreAnimation;
22
using CoreGraphics;
3-
using eShopOnContainers.Core.Effects;
3+
using eShopOnContainers.Core.Behaviors;
44
using eShopOnContainers.iOS.Effects;
55
using System;
66
using System.ComponentModel;
@@ -39,7 +39,7 @@ protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
3939
{
4040
base.OnElementPropertyChanged(args);
4141

42-
if (args.PropertyName == LineColorEffect.LineColorProperty.PropertyName ||
42+
if (args.PropertyName == LineColorBehavior.LineColorProperty.PropertyName ||
4343
args.PropertyName == "Height")
4444
{
4545
Initialize();
@@ -71,7 +71,7 @@ private void UpdateLineColor()
7171
}
7272

7373
lineLayer.Frame = new CGRect(0f, Control.Frame.Height - 1f, Control.Bounds.Width, 1f);
74-
lineLayer.BorderColor = LineColorEffect.GetLineColor(Element).ToCGColor();
74+
lineLayer.BorderColor = LineColorBehavior.GetLineColor(Element).ToCGColor();
7575
control.TintColor = control.TextColor;
7676
}
7777

0 commit comments

Comments
 (0)