summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-12-27 12:58:48 -0600
committerE.Z. Hart <hartez@users.noreply.github.com>2016-12-27 11:58:48 -0700
commitc1d83aacba24f35f056be5b7e792096650d9b7be (patch)
tree715f8f7d597cdea80f76fe423b3740d1abb3205b /Xamarin.Forms.Controls.Issues
parentc34016dc84a30a351d9323285b68ce6cb02af969 (diff)
downloadxamarin-forms-c1d83aacba24f35f056be5b7e792096650d9b7be.tar.gz
xamarin-forms-c1d83aacba24f35f056be5b7e792096650d9b7be.tar.bz2
xamarin-forms-c1d83aacba24f35f056be5b7e792096650d9b7be.zip
[UWP] Fix TextBox style for foreground focus color (#618)
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41054.cs118
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
2 files changed, 119 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41054.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41054.cs
new file mode 100644
index 00000000..27dddfe3
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41054.cs
@@ -0,0 +1,118 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using System.Linq;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+// Apply the default category of "Issues" to all of the tests in this assembly
+// We use this as a catch-all for tests which haven't been individually categorized
+#if UITEST
+[assembly: NUnit.Framework.Category("Issues")]
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ public class Bugzilla41054NumericValidationBehavior : Behavior<Entry>
+ {
+ public static readonly BindableProperty AttachBehaviorProperty =
+ BindableProperty.CreateAttached("AttachBehavior", typeof(bool), typeof(Bugzilla41054NumericValidationBehavior), false, propertyChanged: OnAttachBehaviorChanged);
+
+ public static bool GetAttachBehavior(BindableObject view)
+ {
+ return (bool)view.GetValue(AttachBehaviorProperty);
+ }
+
+ public static void SetAttachBehavior(BindableObject view, bool value)
+ {
+ view.SetValue(AttachBehaviorProperty, value);
+ }
+
+ static void OnAttachBehaviorChanged(BindableObject view, object oldValue, object newValue)
+ {
+ var entry = view as Entry;
+ if (entry == null)
+ {
+ return;
+ }
+
+ bool attachBehavior = (bool)newValue;
+ if (attachBehavior)
+ {
+ entry.Behaviors.Add(new Bugzilla41054NumericValidationBehavior());
+ }
+ else
+ {
+ var toRemove = entry.Behaviors.FirstOrDefault(b => b is Bugzilla41054NumericValidationBehavior);
+ if (toRemove != null)
+ {
+ entry.Behaviors.Remove(toRemove);
+ }
+ }
+ }
+
+ protected override void OnAttachedTo(Entry entry)
+ {
+ entry.TextChanged += OnEntryTextChanged;
+ base.OnAttachedTo(entry);
+ }
+
+ protected override void OnDetachingFrom(Entry entry)
+ {
+ entry.TextChanged -= OnEntryTextChanged;
+ base.OnDetachingFrom(entry);
+ }
+
+ void OnEntryTextChanged(object sender, TextChangedEventArgs args)
+ {
+ double result;
+ bool isValid = double.TryParse(args.NewTextValue, out result);
+ ((Entry)sender).TextColor = isValid ? Color.Default : Color.Red;
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 41054, "Cannot update Entry.Text from attached Behavior on UWP", PlatformAffected.Default)]
+ public class Bugzilla41054 : TestContentPage
+ {
+ protected override void Init()
+ {
+ var entry = new Entry
+ {
+ Placeholder = "Enter a System.Double; text will be red when invalid",
+ PlaceholderColor = Color.Green,
+ };
+ var entry2 = new Entry
+ {
+ Placeholder = "This entry starts with blue text when typing",
+ TextColor = Color.Blue
+ };
+
+ Bugzilla41054NumericValidationBehavior.SetAttachBehavior(entry, true);
+
+ Content = new StackLayout
+ {
+ Children = {
+ entry,
+ entry2,
+ new Entry
+ {
+ Text = "This is an entry with some default colored text"
+ },
+ new Button
+ {
+ Text = "Change first entry placeholder color to purple",
+ Command = new Command(() => entry.PlaceholderColor = Color.Purple)
+ },
+ new Button
+ {
+ Text = "Change second entry text color to orange",
+ Command = new Command(() => entry2.TextColor = Color.Orange)
+ }
+ }
+ };
+ }
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index fe0df146..895bcc9c 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -115,6 +115,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40824.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40911.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40955.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41054.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41205.cs" />