[Bug] Fix ClearButtonVisibility.Never does not take effect on UWP (#9250)
* Setup Issue Page * Update VSM to remove delete button Fixes #8836
This commit is contained in:
Родитель
f88335677a
Коммит
c669481410
|
@ -0,0 +1,48 @@
|
||||||
|
using Xamarin.Forms.CustomAttributes;
|
||||||
|
using Xamarin.Forms.Internals;
|
||||||
|
|
||||||
|
namespace Xamarin.Forms.Controls.Issues
|
||||||
|
{
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
|
[Issue(IssueTracker.Github, 8836, "[Bug] ClearButtonVisibility.Never does not take effect on UWP", PlatformAffected.UWP)]
|
||||||
|
public class Issue8836 : TestContentPage
|
||||||
|
{
|
||||||
|
protected override void Init()
|
||||||
|
{
|
||||||
|
var stack = new StackLayout();
|
||||||
|
|
||||||
|
stack.Children.Add(new Label {Text = "Click the button to toggle the clear button visibility."});
|
||||||
|
|
||||||
|
Entry = new Entry
|
||||||
|
{
|
||||||
|
Text = "Clear Button: While Editing",
|
||||||
|
ClearButtonVisibility = ClearButtonVisibility.WhileEditing
|
||||||
|
};
|
||||||
|
stack.Children.Add(Entry);
|
||||||
|
|
||||||
|
var button = new Button { Text = "Toggle Clear Button State" };
|
||||||
|
button.Clicked += Button_Clicked;
|
||||||
|
stack.Children.Add(button);
|
||||||
|
|
||||||
|
Content = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Clicked(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (Entry.ClearButtonVisibility == ClearButtonVisibility.Never)
|
||||||
|
{
|
||||||
|
Entry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
|
||||||
|
Entry.Text = "Clear Button: While Editing";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Entry.ClearButtonVisibility = ClearButtonVisibility.Never;
|
||||||
|
Entry.Text = "Clear Button: Never";
|
||||||
|
}
|
||||||
|
Entry.Focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entry Entry { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,7 @@
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8262.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue8262.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8899.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue8899.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8551.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue8551.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Issue8836.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8902.xaml.cs">
|
<Compile Include="$(MSBuildThisFileDirectory)Issue8902.xaml.cs">
|
||||||
<DependentUpon>Issue8902.xaml</DependentUpon>
|
<DependentUpon>Issue8902.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
|
|
|
@ -66,6 +66,9 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
UpdateReturnType();
|
UpdateReturnType();
|
||||||
UpdateIsReadOnly();
|
UpdateIsReadOnly();
|
||||||
UpdateInputScope();
|
UpdateInputScope();
|
||||||
|
UpdateClearButtonVisibility();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_cursorPositionChangePending)
|
if (_cursorPositionChangePending)
|
||||||
UpdateCursorPosition();
|
UpdateCursorPosition();
|
||||||
|
@ -148,6 +151,8 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
UpdateSelectionLength();
|
UpdateSelectionLength();
|
||||||
else if (e.PropertyName == InputView.IsReadOnlyProperty.PropertyName)
|
else if (e.PropertyName == InputView.IsReadOnlyProperty.PropertyName)
|
||||||
UpdateIsReadOnly();
|
UpdateIsReadOnly();
|
||||||
|
else if (e.PropertyName == Entry.ClearButtonVisibilityProperty.PropertyName)
|
||||||
|
UpdateClearButtonVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateBackgroundColor()
|
protected override void UpdateBackgroundColor()
|
||||||
|
@ -236,6 +241,11 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
Control.CharacterSpacing = Element.CharacterSpacing.ToEm();
|
Control.CharacterSpacing = Element.CharacterSpacing.ToEm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateClearButtonVisibility()
|
||||||
|
{
|
||||||
|
Control.ClearButtonVisible = Element.ClearButtonVisibility == ClearButtonVisibility.WhileEditing;
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateInputScope()
|
void UpdateInputScope()
|
||||||
{
|
{
|
||||||
Entry entry = Element;
|
Entry entry = Element;
|
||||||
|
|
|
@ -42,9 +42,15 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
public new static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text),
|
public new static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text),
|
||||||
typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged));
|
typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty ClearButtonVisibleProperty = DependencyProperty.Register(nameof(ClearButtonVisible),
|
||||||
|
typeof(bool), typeof(FormsTextBox), new PropertyMetadata(true, ClearButtonVisibleChanged));
|
||||||
|
|
||||||
InputScope _passwordInputScope;
|
InputScope _passwordInputScope;
|
||||||
InputScope _numericPasswordInputScope;
|
InputScope _numericPasswordInputScope;
|
||||||
Border _borderElement;
|
Border _borderElement;
|
||||||
|
Windows.UI.Xaml.Controls.Grid _rootGrid;
|
||||||
|
Windows.UI.Xaml.VisualState _DeleteButtonVisibleState;
|
||||||
|
Windows.UI.Xaml.VisualStateGroup _DeleteButtonVisibleStateGroups;
|
||||||
InputScope _cachedInputScope;
|
InputScope _cachedInputScope;
|
||||||
bool _cachedPredictionsSetting;
|
bool _cachedPredictionsSetting;
|
||||||
bool _cachedSpellCheckSetting;
|
bool _cachedSpellCheckSetting;
|
||||||
|
@ -64,6 +70,12 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
UpdateEnabled();
|
UpdateEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ClearButtonVisible
|
||||||
|
{
|
||||||
|
get { return (bool)GetValue(ClearButtonVisibleProperty); }
|
||||||
|
set { SetValue(ClearButtonVisibleProperty, value);}
|
||||||
|
}
|
||||||
|
|
||||||
public Brush BackgroundFocusBrush
|
public Brush BackgroundFocusBrush
|
||||||
{
|
{
|
||||||
get { return (Brush)GetValue(BackgroundFocusBrushProperty); }
|
get { return (Brush)GetValue(BackgroundFocusBrushProperty); }
|
||||||
|
@ -146,6 +158,15 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
// so we can manually handle its background when focused
|
// so we can manually handle its background when focused
|
||||||
_borderElement = (Border)GetTemplateChild("BorderElement");
|
_borderElement = (Border)GetTemplateChild("BorderElement");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_rootGrid = (Windows.UI.Xaml.Controls.Grid)GetTemplateChild("RootGrid");
|
||||||
|
if (_rootGrid != null)
|
||||||
|
{
|
||||||
|
var stateGroups = WVisualStateManager.GetVisualStateGroups(_rootGrid).ToList();
|
||||||
|
_DeleteButtonVisibleStateGroups = stateGroups.SingleOrDefault(sg => sg.Name == "ButtonStates");
|
||||||
|
if (_DeleteButtonVisibleStateGroups != null)
|
||||||
|
_DeleteButtonVisibleState = _DeleteButtonVisibleStateGroups.States.SingleOrDefault(s => s.Name == "ButtonVisible");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelayObfuscation()
|
void DelayObfuscation()
|
||||||
|
@ -346,6 +367,21 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
SelectionStart = base.Text.Length;
|
SelectionStart = base.Text.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ClearButtonVisibleChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||||
|
{
|
||||||
|
var textBox = (FormsTextBox)dependencyObject;
|
||||||
|
var visibleState = textBox._DeleteButtonVisibleState;
|
||||||
|
var states = textBox._DeleteButtonVisibleStateGroups?.States;
|
||||||
|
|
||||||
|
if (states != null && visibleState != null)
|
||||||
|
{
|
||||||
|
if (textBox.ClearButtonVisible && !states.Contains(visibleState))
|
||||||
|
states.Add(visibleState);
|
||||||
|
else
|
||||||
|
states.Remove(visibleState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void TextPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
static void TextPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||||
{
|
{
|
||||||
var textBox = (FormsTextBox)dependencyObject;
|
var textBox = (FormsTextBox)dependencyObject;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="uwp:FormsTextBox">
|
<ControlTemplate TargetType="uwp:FormsTextBox">
|
||||||
<Grid>
|
<Grid x:Name="RootGrid">
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
<Style x:Name="DeleteButtonStyle" TargetType="Button">
|
<Style x:Name="DeleteButtonStyle" TargetType="Button">
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
|
|
Загрузка…
Ссылка в новой задаче