summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
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/EntryRenderer.cs
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/EntryRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/EntryRenderer.cs62
1 files changed, 21 insertions, 41 deletions
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