diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-10-18 16:53:56 -0600 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-10-18 23:55:29 +0100 |
commit | 32e739891f120e164b4b837fb984e5db8105ab01 (patch) | |
tree | ce786f8ab29d8e5dc877dea6fc71c541a8ab6ff4 | |
parent | 90c2f228f1e3371783bac1e3ad12b42d94970b40 (diff) | |
download | xamarin-forms-32e739891f120e164b4b837fb984e5db8105ab01.tar.gz xamarin-forms-32e739891f120e164b4b837fb984e5db8105ab01.tar.bz2 xamarin-forms-32e739891f120e164b4b837fb984e5db8105ab01.zip |
Stop forcing FormsTextBox content to ForegroundFocusBrush on UWP (#1206)
-rw-r--r-- | Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/FormsTextBox.cs | 40 |
2 files changed, 33 insertions, 9 deletions
diff --git a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml index 0e147d7f..0003a813 100644 --- a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml +++ b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml @@ -178,7 +178,7 @@ Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}" FontWeight="Normal" Margin="0,0,0,8" Grid.Row="0" Visibility="Collapsed" x:DeferLoadStrategy="Lazy" /> <ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" - Foreground="{TemplateBinding ForegroundFocusBrush}" + HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" diff --git a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs index 4301dd0a..03d189c7 100644 --- a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs +++ b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs @@ -24,19 +24,27 @@ namespace Xamarin.Forms.Platform.WinRT { const char ObfuscationCharacter = '●'; - public static readonly DependencyProperty PlaceholderForegroundBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundBrush), typeof(Brush), typeof(FormsTextBox), - new PropertyMetadata(default(Brush))); + public static readonly DependencyProperty PlaceholderForegroundBrushProperty = + DependencyProperty.Register(nameof(PlaceholderForegroundBrush), typeof(Brush), typeof(FormsTextBox), + new PropertyMetadata(default(Brush), FocusPropertyChanged)); - public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox), - new PropertyMetadata(default(Brush))); + public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = + DependencyProperty.Register(nameof(PlaceholderForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox), + new PropertyMetadata(default(Brush), FocusPropertyChanged)); - public static readonly DependencyProperty ForegroundFocusBrushProperty = DependencyProperty.Register(nameof(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), FocusPropertyChanged)); - public static readonly DependencyProperty BackgroundFocusBrushProperty = DependencyProperty.Register(nameof(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), FocusPropertyChanged)); - public static readonly DependencyProperty IsPasswordProperty = DependencyProperty.Register(nameof(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(nameof(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)); InputScope passwordInputScope; Border _borderElement; @@ -374,5 +382,21 @@ namespace Xamarin.Forms.Platform.WinRT IsTextPredictionEnabled = _cachedPredictionsSetting; } } + + static void FocusPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + // If we're modifying the properties related to the focus state of the control (e.g., + // ForegroundFocusBrush), the changes won't be reflected immediately because they are only applied + // when the Windows.UI.XAML.VisualStateManager moves to the "Focused" state. So we have to force a + // "refresh" of the Focused state by going to that state again + + var control = dependencyObject as Control; + if (control == null || control.FocusState == FocusState.Unfocused) + { + return; + } + + VisualStateManager.GoToState(control, "Focused", false); + } } }
\ No newline at end of file |