Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29962.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29962, "[Windows] SearchBar PlaceHolder and Background Color should update properly at runtime", PlatformAffected.UWP)]
public class Issue29962 : ContentPage
{
public Issue29962()
{
var searchBar = new SearchBar
{
Placeholder = "Search here...",
Margin = new Thickness(0, 30),
BackgroundColor = Colors.Black,
PlaceholderColor = Colors.Yellow,
HeightRequest = 50,
};
var button = new Button
{
Text = "Change PlaceHolder and Background Color",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "ColorChangeButton"
};
button.Clicked += (sender, e) =>
{
searchBar.BackgroundColor = Colors.YellowGreen;
searchBar.PlaceholderColor = Colors.Red;
};

Content = new StackLayout
{
Children =
{
searchBar,
button
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29962 : _IssuesUITest
{
public override string Issue => "[Windows] SearchBar PlaceHolder and Background Color should update properly at runtime";

public Issue29962(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.SearchBar)]
public void VerifySearchBarPlaceholderAndBackgroundColor()
{
App.WaitForElement("ColorChangeButton");
App.Tap("ColorChangeButton");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 25 additions & 9 deletions src/Core/src/Platform/Windows/SearchBarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Platform
{
public static class SearchBarExtensions
{
private static readonly string[] _backgroundColorKeys =
static readonly string[] _backgroundColorKeys =
{
"TextControlBackground",
"TextControlBackgroundPointerOver",
Expand All @@ -17,7 +17,7 @@ public static class SearchBarExtensions

public static void UpdateBackground(this AutoSuggestBox platformControl, ISearchBar searchBar)
{
UpdateColors(platformControl.Resources, _backgroundColorKeys, searchBar.Background?.ToPlatform());
UpdateColors(platformControl, platformControl.Resources, _backgroundColorKeys, searchBar.Background?.ToPlatform());
}

public static void UpdateIsEnabled(this AutoSuggestBox platformControl, ISearchBar searchBar)
Expand All @@ -35,7 +35,7 @@ public static void UpdatePlaceholder(this AutoSuggestBox platformControl, ISearc
platformControl.PlaceholderText = searchBar.Placeholder ?? string.Empty;
}

private static readonly string[] _placeholderForegroundColorKeys =
static readonly string[] _placeholderForegroundColorKeys =
{
"TextControlPlaceholderForeground",
"TextControlPlaceholderForegroundPointerOver",
Expand All @@ -45,7 +45,7 @@ public static void UpdatePlaceholder(this AutoSuggestBox platformControl, ISearc

public static void UpdatePlaceholderColor(this AutoSuggestBox platformControl, ISearchBar searchBar)
{
UpdateColors(platformControl.Resources, _placeholderForegroundColorKeys,
UpdateColors(platformControl, platformControl.Resources, _placeholderForegroundColorKeys,
searchBar.PlaceholderColor?.ToPlatform());
}

Expand All @@ -54,7 +54,7 @@ public static void UpdateText(this AutoSuggestBox platformControl, ISearchBar se
platformControl.Text = searchBar.Text;
}

private static readonly string[] _foregroundColorKeys =
static readonly string[] _foregroundColorKeys =
{
"TextControlForeground",
"TextControlForegroundPointerOver",
Expand All @@ -66,7 +66,7 @@ public static void UpdateTextColor(this AutoSuggestBox platformControl, ISearchB
{
var tintBrush = searchBar.TextColor?.ToPlatform();

if (tintBrush == null)
if (tintBrush is null)
{
platformControl.Resources.RemoveKeys(_foregroundColorKeys);
platformControl.Foreground = null;
Expand All @@ -80,7 +80,7 @@ public static void UpdateTextColor(this AutoSuggestBox platformControl, ISearchB
platformControl.RefreshThemeResources();
}

private static void UpdateColors(ResourceDictionary resource, string[] keys, Brush? brush)
private static void UpdateColors(AutoSuggestBox platformControl, ResourceDictionary resource, string[] keys, Brush? brush)
{
if (brush is null)
{
Expand All @@ -90,6 +90,8 @@ private static void UpdateColors(ResourceDictionary resource, string[] keys, Bru
{
resource.SetValueForAllKey(keys, brush);
}

platformControl.RefreshThemeResources();
}

public static void UpdateFont(this AutoSuggestBox platformControl, ISearchBar searchBar, IFontManager fontManager) =>
Expand Down Expand Up @@ -126,14 +128,20 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB
}

if (maxLength == 0)
{
MauiAutoSuggestBox.SetIsReadOnly(platformControl, true);
}
else
{
MauiAutoSuggestBox.SetIsReadOnly(platformControl, searchBar.IsReadOnly);
}

var currentControlText = platformControl.Text;

if (currentControlText.Length > maxLength)
{
platformControl.Text = currentControlText.Substring(0, maxLength);
}
}

public static void UpdateIsReadOnly(this AutoSuggestBox platformControl, ISearchBar searchBar)
Expand All @@ -146,7 +154,9 @@ public static void UpdateIsTextPredictionEnabled(this AutoSuggestBox platformCon
var textBox = platformControl.GetFirstDescendant<TextBox>();

if (textBox is null)
{
return;
}

textBox.UpdateIsTextPredictionEnabled(searchBar);
}
Expand All @@ -156,7 +166,9 @@ public static void UpdateIsSpellCheckEnabled(this AutoSuggestBox platformControl
var textBox = platformControl.GetFirstDescendant<TextBox>();

if (textBox is null)
{
return;
}

textBox.UpdateIsSpellCheckEnabled(searchBar);
}
Expand All @@ -165,13 +177,15 @@ public static void UpdateKeyboard(this AutoSuggestBox platformControl, ISearchBa
{
var queryTextBox = platformControl.GetFirstDescendant<TextBox>();

if (queryTextBox == null)
if (queryTextBox is null)
{
return;
}

queryTextBox.UpdateInputScope(searchBar);
}

private static readonly string[] CancelButtonColorKeys =
static readonly string[] CancelButtonColorKeys =
{
"TextControlButtonForeground",
"TextControlButtonForegroundPointerOver",
Expand All @@ -183,7 +197,9 @@ internal static void UpdateCancelButtonColor(this AutoSuggestBox platformControl
var cancelButton = platformControl.GetDescendantByName<Button>("DeleteButton");

if (cancelButton is null)
{
return;
}

cancelButton.UpdateTextColor(searchBar.CancelButtonColor, CancelButtonColorKeys);
}
Expand Down
Loading