summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2017-03-03 06:31:46 -0600
committerRui Marinho <me@ruimarinho.net>2017-03-03 12:31:46 +0000
commit8871077f115e7ef4d15efaa418fd718089db42c7 (patch)
tree91faf77329b6c1be984f36665ea80d6ae6a57589
parent38c0b34e91e2148e78704432afec6b086c9fc0c9 (diff)
downloadxamarin-forms-8871077f115e7ef4d15efaa418fd718089db42c7.tar.gz
xamarin-forms-8871077f115e7ef4d15efaa418fd718089db42c7.tar.bz2
xamarin-forms-8871077f115e7ef4d15efaa418fd718089db42c7.zip
[WinRT/UWP] Make TextBox better respect background color changes via behaviors (#749)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44955.cs81
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml2
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml6
-rw-r--r--Xamarin.Forms.Platform.WinRT.Tablet/FormsTextBoxStyle.xaml14
5 files changed, 101 insertions, 3 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44955.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44955.cs
new file mode 100644
index 00000000..a30a65bd
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44955.cs
@@ -0,0 +1,81 @@
+using System.Diagnostics;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 44955, "[WinRT/UWP] Setting Entry BackgroundColor via Behavior results in sticky unfocused background color", PlatformAffected.WinRT)]
+ public class Bugzilla44955 : TestContentPage
+ {
+ Entry _validationEntry;
+ protected override void Init()
+ {
+ _validationEntry = new Entry();
+ _validationEntry.Behaviors.Add(new NonEmptyStringValidator());
+ Content = new StackLayout
+ {
+ Children =
+ {
+ new Label
+ {
+ Text = "The first entry should have a red background only when it is empty, regardless of focus (due to an attached behavior). The second has a set background color, the third is default, and the last is default, but disabled."
+ },
+ _validationEntry,
+ new Entry
+ {
+ BackgroundColor = Color.MediumPurple
+ },
+ new Entry(),
+ new Entry
+ {
+ IsEnabled = false
+ },
+ new Button
+ {
+ Text = "Change background of first label to yellow",
+ Command = new Command(() => _validationEntry.BackgroundColor = Color.Yellow)
+ }
+ }
+ };
+ }
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ _validationEntry.Behaviors.Clear();
+ }
+
+ class NonEmptyStringValidator : Behavior<Entry>
+ {
+ protected override void OnAttachedTo(Entry bindable)
+ {
+ bindable.TextChanged += HandleTextChanged;
+ Validate(bindable, bindable.Text);
+ }
+
+ protected override void OnDetachingFrom(Entry bindable)
+ {
+ bindable.TextChanged -= HandleTextChanged;
+ }
+
+ void HandleTextChanged(object sender, TextChangedEventArgs e)
+ {
+ Validate((Entry)sender, e.NewTextValue);
+ }
+
+ void Validate(Entry entry, string text)
+ {
+ if (text == null)
+ entry.BackgroundColor = Color.Red;
+ else
+ entry.BackgroundColor = text.Trim() != "" ? Color.Default : Color.Red;
+ }
+ }
+ }
+}
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 1093f1b0..0deca6b6 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
@@ -164,6 +164,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45027.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45330.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44955.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45743.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla46494.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44476.cs" />
diff --git a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml
index 4d9ea090..ad9f0b97 100644
--- a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml
+++ b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml
@@ -166,7 +166,7 @@
<Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" Grid.ColumnSpan="2"
Margin="{TemplateBinding BorderThickness}" Opacity="{ThemeResource TextControlBackgroundRestOpacity}"
Grid.Row="1" Grid.RowSpan="1" />
- <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}"
+ <Border x:Name="BorderElement" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="1" />
<ContentPresenter x:Name="HeaderContentPresenter" Grid.ColumnSpan="2"
ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}"
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml
index 521a9059..3f3cced7 100644
--- a/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml
+++ b/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml
@@ -48,7 +48,10 @@
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter">
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ContentElement">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" />
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter">
@@ -90,6 +93,7 @@
Grid.Row="0" Style="{StaticResource HeaderContentPresenterStyle}"/>
<ScrollViewer x:Name="ContentElement"
AutomationProperties.AccessibilityView="Raw"
+ Background="{Binding BackgroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
IsTabStop="False"
diff --git a/Xamarin.Forms.Platform.WinRT.Tablet/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.WinRT.Tablet/FormsTextBoxStyle.xaml
index 3e5f5646..c385d53e 100644
--- a/Xamarin.Forms.Platform.WinRT.Tablet/FormsTextBoxStyle.xaml
+++ b/Xamarin.Forms.Platform.WinRT.Tablet/FormsTextBoxStyle.xaml
@@ -123,12 +123,22 @@
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
+ Storyboard.TargetProperty="Background">
+ <DiscreteObjectKeyFrame KeyTime="0"
+ Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" />
+ </ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextBoxDisabledBorderThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
+ Storyboard.TargetProperty="Background">
+ <DiscreteObjectKeyFrame KeyTime="0"
+ Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" />
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}" />
@@ -198,6 +208,7 @@
Grid.ColumnSpan="2"
Grid.RowSpan="1" />
<Border x:Name="BorderElement"
+ Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
Grid.Row="1"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
@@ -212,6 +223,7 @@
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="Semilight" />
<ScrollViewer x:Name="ContentElement"
+ Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
Grid.Row="1"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"