Stop forcing FormsTextBox content to ForegroundFocusBrush on UWP (#1206)

This commit is contained in:
E.Z. Hart 2017-10-18 16:53:56 -06:00 коммит произвёл Rui Marinho
Родитель 90c2f228f1
Коммит 32e739891f
2 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@ -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}"

Просмотреть файл

@ -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);
}
}
}