Skip to content

Commit 97251c0

Browse files
Ahamed-Alijsuarezruiz
authored andcommitted
[Windows] Fixed the text and icon color issues in the DatePicker when hovering over it. (#27147)
* Fixed the Hovering issue of text and icon color in the DatePicker in windows. * Included the UI test sample and test case * Modified the test * Added Device Test --------- Co-authored-by: Javier Suárez <[email protected]>
1 parent 8542fa8 commit 97251c0

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.ComponentModel;
2+
using System.Threading.Tasks;
3+
using Microsoft.Maui.Graphics;
4+
using Microsoft.Maui.Handlers;
5+
using Microsoft.Maui.Platform;
6+
using Microsoft.UI.Xaml.Controls;
7+
using Xunit;
8+
using WSolidColorBrush = Microsoft.UI.Xaml.Media.SolidColorBrush;
9+
10+
namespace Microsoft.Maui.DeviceTests;
11+
12+
public partial class DatePickerTests
13+
{
14+
[Fact]
15+
[Description("The DatePicker Text and Icon Color should work properly on PointerOver")]
16+
public async Task DatePickerTextAndIconColorShouldWorkProperlyOnPointerOver()
17+
{
18+
SetupBuilder();
19+
20+
var datePicker = new Controls.DatePicker
21+
{
22+
TextColor = Colors.Red
23+
};
24+
var expectedValue = datePicker.TextColor;
25+
26+
var handler = await CreateHandlerAsync<DatePickerHandler>(datePicker);
27+
var platformView = GetPlatformControl(handler);
28+
29+
await InvokeOnMainThreadAsync(() =>
30+
{
31+
var foregroundPointerOverBrush = platformView.Resources["CalendarDatePickerTextForegroundPointerOver"] as WSolidColorBrush;
32+
var foregroundPointerOverColor = foregroundPointerOverBrush.Color.ToColor();
33+
Assert.Equal(expectedValue, foregroundPointerOverColor);
34+
35+
var glyphForegroundPointerOverBrush = platformView.Resources["CalendarDatePickerCalendarGlyphForegroundPointerOver"] as WSolidColorBrush;
36+
var glyphForegroundPointerOverColor = glyphForegroundPointerOverBrush.Color.ToColor();
37+
Assert.Equal(expectedValue, glyphForegroundPointerOverColor);
38+
});
39+
}
40+
41+
static CalendarDatePicker GetPlatformControl(DatePickerHandler handler) =>
42+
handler.PlatformView;
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Handlers;
3+
using Microsoft.Maui.Hosting;
4+
5+
namespace Microsoft.Maui.DeviceTests;
6+
7+
[Category(TestCategory.DatePicker)]
8+
public partial class DatePickerTests : ControlsHandlerTestBase
9+
{
10+
void SetupBuilder()
11+
{
12+
EnsureHandlerCreated(builder =>
13+
{
14+
builder.ConfigureMauiHandlers(handlers =>
15+
{
16+
handlers.AddHandler<DatePicker, DatePickerHandler>();
17+
});
18+
});
19+
}
20+
}

src/Controls/tests/DeviceTests/TestCategory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class TestCategory
1313
public const string CollectionView = "CollectionView";
1414
public const string Compatibility = "Compatibility";
1515
public const string ContentView = "ContentView";
16+
public const string DatePicker = nameof(DatePicker);
1617
public const string Dispatcher = "Dispatcher";
1718
public const string Editor = "Editor";
1819
public const string Element = "Element";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue22987">
5+
<ContentPage.Resources>
6+
<Style TargetType="DatePicker">
7+
<Setter Property="VisualStateManager.VisualStateGroups">
8+
<VisualStateGroupList>
9+
<VisualStateGroup Name="CommonStates">
10+
<VisualState Name="Normal">
11+
<VisualState.Setters>
12+
<Setter Property="TextColor" Value="white" />
13+
</VisualState.Setters>
14+
</VisualState>
15+
16+
<VisualState Name="PointerOver">
17+
<VisualState.Setters>
18+
<Setter Property="TextColor" Value="yellow" />
19+
</VisualState.Setters>
20+
</VisualState>
21+
</VisualStateGroup>
22+
</VisualStateGroupList>
23+
</Setter>
24+
</Style>
25+
</ContentPage.Resources>
26+
27+
<VerticalStackLayout VerticalOptions="Center" HorizontalOptions="Center">
28+
<Label Text="DatePicker" AutomationId="Label"/>
29+
<DatePicker BackgroundColor="Black" Date="01/15/2025" />
30+
</VerticalStackLayout>
31+
</ContentPage>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 22987, "DatePicker Color Icon", PlatformAffected.UWP)]
4+
public partial class Issue22987 : ContentPage
5+
{
6+
public Issue22987()
7+
{
8+
InitializeComponent();
9+
}
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_IOS
2+
// In MacCatalyst, DatePicker Text color property is not working MacOS https://github.com/dotnet/maui/issues/20904
3+
// In Windows, Once this PR https://github.com/dotnet/maui/pull/27477 merged, we can implement the MoveCursor and enable the test
4+
using NUnit.Framework;
5+
using UITest.Appium;
6+
using UITest.Core;
7+
8+
namespace Microsoft.Maui.TestCases.Tests.Issues;
9+
10+
public class Issue22987 : _IssuesUITest
11+
{
12+
public Issue22987(TestDevice device) : base(device) { }
13+
14+
public override string Issue => "DatePicker Color Icon";
15+
16+
[Test]
17+
[Category(UITestCategories.DatePicker)]
18+
public void DatePickerTextandIconColorShouldWorkProperlyOnPointerOver()
19+
{
20+
App.WaitForElement("Label");
21+
22+
//need to include something like a MovePointer and MovePointerToCoordinate methods for hovering.
23+
24+
VerifyScreenshot();
25+
}
26+
}
27+
#endif

src/Core/src/Platform/Windows/DatePickerExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ public static void UpdateTextColor(this CalendarDatePicker platformDatePicker, I
6969
static readonly string[] TextColorResourceKeys =
7070
{
7171
"CalendarDatePickerTextForeground",
72+
"CalendarDatePickerTextForegroundPointerOver",
73+
"CalendarDatePickerTextForegroundPressed",
7274
"CalendarDatePickerTextForegroundDisabled",
73-
"CalendarDatePickerTextForegroundSelected"
75+
"CalendarDatePickerTextForegroundSelected",
76+
77+
// below resource keys are used for the calendar icon
78+
"CalendarDatePickerCalendarGlyphForeground",
79+
"CalendarDatePickerCalendarGlyphForegroundPointerOver",
80+
"CalendarDatePickerCalendarGlyphForegroundPressed",
81+
"CalendarDatePickerCalendarGlyphForegroundDisabled",
7482
};
7583

7684
// TODO NET8 add to public API

0 commit comments

Comments
 (0)