summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-08-16 12:10:32 -0600
committerJason Smith <jason.smith@xamarin.com>2016-08-16 11:10:32 -0700
commit30c0dcb949186c21c60c4c9ddf8a581d40a43662 (patch)
tree17a196012b9d4044f78cc0acbe9aa137d10f2b25 /Xamarin.Forms.Platform.WinRT
parent966683a807f68f302e8f121279387109f2a4a73b (diff)
downloadxamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.tar.gz
xamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.tar.bz2
xamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.zip
Fix Entry/SearchBar color issues (#306)
* Fix disappearing Entry text on UWP Anniversary Edition Fix background color reversion bug in UWP Phone Move SearchBar styling on UWP to its own file Make foreground/background color changes on UWP SearchBar/Entry consistent Fix SearchBar color toggle bug on WP8 * Temporarily moving SDK target to previous version * Fix build error on OSX
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/BrushHelpers.cs43
-rw-r--r--Xamarin.Forms.Platform.WinRT/EntryRenderer.cs62
-rw-r--r--Xamarin.Forms.Platform.WinRT/FormsTextBox.cs16
-rw-r--r--Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj1
4 files changed, 74 insertions, 48 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs b/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs
new file mode 100644
index 00000000..ae158b8f
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs
@@ -0,0 +1,43 @@
+using System;
+using Windows.UI.Xaml.Media;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ internal static class BrushHelpers
+ {
+ /// <summary>
+ /// Handles the logic for setting a Xamarin.Forms Color for a Brush
+ /// while caching the original default brush
+ /// </summary>
+ /// <param name="color">The target Xamarin.Forms.Color</param>
+ /// <param name="defaultbrush">The renderer's cache for the default brush</param>
+ /// <param name="getter">Delegate for retrieving the Control's current Brush</param>
+ /// <param name="setter">Delegate for setting the Control's Brush</param>
+ public static void UpdateColor(Color color, ref Brush defaultbrush, Func<Brush> getter, Action<Brush> setter)
+ {
+ if (color.IsDefault)
+ {
+ if (defaultbrush == null)
+ {
+ return;
+ }
+
+ setter(defaultbrush);
+ return;
+ }
+
+ if (defaultbrush == null)
+ {
+ defaultbrush = getter();
+ }
+
+ setter(color.ToBrush());
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
index f9f0b3a2..c6e439ea 100644
--- a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
@@ -1,4 +1,7 @@
-using System.ComponentModel;
+using System;
+using System.ComponentModel;
+using System.Reflection;
+using Windows.Foundation.Metadata;
using Windows.System;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
@@ -13,10 +16,12 @@ namespace Xamarin.Forms.Platform.WinRT
{
public class EntryRenderer : ViewRenderer<Entry, FormsTextBox>
{
- Brush _backgroundColorFocusedDefaultBrush;
-
bool _fontApplied;
+ Brush _backgroundColorFocusedDefaultBrush;
Brush _placeholderDefaultBrush;
+ Brush _textDefaultBrush;
+ Brush _defaultTextColorFocusBrush;
+ Brush _defaultPlaceholderColorFocusBrush;
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
@@ -27,7 +32,6 @@ namespace Xamarin.Forms.Platform.WinRT
if (Control == null)
{
var textBox = new FormsTextBox { Style = Windows.UI.Xaml.Application.Current.Resources["FormsTextBoxStyle"] as Windows.UI.Xaml.Style };
-
SetNativeControl(textBox);
textBox.TextChanged += OnNativeTextChanged;
@@ -92,24 +96,8 @@ namespace Xamarin.Forms.Platform.WinRT
}
// By default some platforms have alternate default background colors when focused
- Color backgroundColor = Element.BackgroundColor;
- if (backgroundColor.IsDefault)
- {
- if (_backgroundColorFocusedDefaultBrush == null)
- {
- return;
- }
-
- Control.BackgroundFocusBrush = _backgroundColorFocusedDefaultBrush;
- return;
- }
-
- if (_backgroundColorFocusedDefaultBrush == null)
- {
- _backgroundColorFocusedDefaultBrush = Control.BackgroundFocusBrush;
- }
-
- Control.BackgroundFocusBrush = backgroundColor.ToBrush();
+ BrushHelpers.UpdateColor(Element.BackgroundColor, ref _backgroundColorFocusedDefaultBrush,
+ () => Control.BackgroundFocusBrush, brush => Control.BackgroundFocusBrush = brush);
}
void OnNativeTextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs args)
@@ -190,25 +178,11 @@ namespace Xamarin.Forms.Platform.WinRT
{
Color placeholderColor = Element.PlaceholderColor;
- if (placeholderColor.IsDefault)
- {
- if (_placeholderDefaultBrush == null)
- {
- return;
- }
-
- // Use the cached default brush
- Control.PlaceholderForegroundBrush = _placeholderDefaultBrush;
- return;
- }
-
- if (_placeholderDefaultBrush == null)
- {
- // Cache the default brush in case we need to set the color back to default
- _placeholderDefaultBrush = Control.PlaceholderForegroundBrush;
- }
+ BrushHelpers.UpdateColor(placeholderColor, ref _placeholderDefaultBrush,
+ () => Control.PlaceholderForegroundBrush, brush => Control.PlaceholderForegroundBrush = brush);
- Control.PlaceholderForegroundBrush = placeholderColor.ToBrush();
+ BrushHelpers.UpdateColor(placeholderColor, ref _defaultPlaceholderColorFocusBrush,
+ () => Control.PlaceholderForegroundFocusBrush, brush => Control.PlaceholderForegroundFocusBrush = brush);
}
void UpdateText()
@@ -218,7 +192,13 @@ namespace Xamarin.Forms.Platform.WinRT
void UpdateTextColor()
{
- Control.Foreground = Element.TextColor.ToBrush();
+ Color textColor = Element.TextColor;
+
+ BrushHelpers.UpdateColor(textColor, ref _textDefaultBrush,
+ () => Control.Foreground, brush => Control.Foreground = brush);
+
+ BrushHelpers.UpdateColor(textColor, ref _defaultTextColorFocusBrush,
+ () => Control.ForegroundFocusBrush, brush => Control.ForegroundFocusBrush = brush);
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs
index 03725cd8..4cb74ec7 100644
--- a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs
+++ b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs
@@ -23,19 +23,19 @@ namespace Xamarin.Forms.Platform.WinRT
{
const char ObfuscationCharacter = '●';
- public static readonly DependencyProperty PlaceholderForegroundBrushProperty = DependencyProperty.Register("PlaceholderForegroundBrush", typeof(Brush), typeof(FormsTextBox),
+ public static readonly DependencyProperty PlaceholderForegroundBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundBrush), typeof(Brush), typeof(FormsTextBox),
new PropertyMetadata(default(Brush)));
- public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = DependencyProperty.Register("PlaceholderForegroundFocusBrush", typeof(Brush), typeof(FormsTextBox),
+ public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox),
new PropertyMetadata(default(Brush)));
- public static readonly DependencyProperty ForegroundFocusBrushProperty = DependencyProperty.Register("ForegroundFocusBrush", typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush)));
+ public static readonly DependencyProperty ForegroundFocusBrushProperty = DependencyProperty.Register(nameof(ForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush)));
- public static readonly DependencyProperty BackgroundFocusBrushProperty = DependencyProperty.Register("BackgroundFocusBrush", typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush)));
+ public static readonly DependencyProperty BackgroundFocusBrushProperty = DependencyProperty.Register(nameof(BackgroundFocusBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush)));
- public static readonly DependencyProperty IsPasswordProperty = DependencyProperty.Register("IsPassword", typeof(bool), typeof(FormsTextBox), new PropertyMetadata(default(bool), OnIsPasswordChanged));
+ public static readonly DependencyProperty IsPasswordProperty = DependencyProperty.Register(nameof(IsPassword), typeof(bool), typeof(FormsTextBox), new PropertyMetadata(default(bool), OnIsPasswordChanged));
- public new static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged));
+ public new static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged));
static InputScope s_passwordInputScope;
Border _borderElement;
@@ -120,13 +120,15 @@ namespace Xamarin.Forms.Platform.WinRT
{
base.OnGotFocus(e);
- // If we're on the phone, the Visual State Manager crashes if we try to
+#if !WINDOWS_UWP
+ // If we're on Windows 8.1 phone, the Visual State Manager crashes if we try to
// handle alternate background colors in the focus state; we have to do
// it manually here
if (Device.Idiom == TargetIdiom.Phone && _borderElement != null)
{
_borderElement.Background = BackgroundFocusBrush;
}
+#endif
}
void DelayObfuscation()
diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
index f6b3566a..400737d0 100644
--- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
+++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
@@ -68,6 +68,7 @@
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(OS)' != 'Unix' ">
+ <Compile Include="BrushHelpers.cs" />
<Compile Include="NativeViewWrapper.cs" />
<Compile Include="NativeViewWrapperRenderer.cs" />
<Compile Include="ViewExtensions.cs" />