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.
46 changes: 46 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25921.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 25921, "[Windows] Setting BackgroundColor for Slider updates the Maximum Track Color", PlatformAffected.UWP)]
public class Issue25921 : ContentPage
{
public Issue25921()
{
var layout = new VerticalStackLayout();
layout.VerticalOptions = LayoutOptions.Center;
layout.Spacing = 20;
var slider = new Slider()
{
WidthRequest = 300,
Maximum = 100,
Minimum = 0,
Value = 50,
BackgroundColor = Colors.Yellow,
MaximumTrackColor = Colors.Red,
MinimumTrackColor = Colors.Fuchsia,
};

var secondSlider = new Slider()
{
WidthRequest = 300,
Maximum = 100,
Minimum = 0,
Value = 50,
Background = Colors.Grey,
MaximumTrackColor = Colors.SpringGreen,
MinimumTrackColor = Colors.BlueViolet,
};

var button = new Button()
{
Text = "Change Background Color",
AutomationId = "ColorChangeButton",
Command = new Command(() => secondSlider.Background = Colors.Salmon)
};

layout.Children.Add(slider);
layout.Children.Add(secondSlider);
layout.Children.Add(button);

Content = layout;
}
}
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
@@ -1,6 +1,4 @@
#if TEST_FAILS_ON_WINDOWS //Background Color updates on Slider Track
//For more information : https://github.com/dotnet/maui/issues/25921
using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -23,5 +21,4 @@ public void Bugzilla29128Test()
VerifyScreenshot();
}
}
}
#endif
}
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 Issue25921 : _IssuesUITest
{
public override string Issue => "[Windows] Setting BackgroundColor for Slider updates the Maximum Track Color";

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

[Test]
[Category(UITestCategories.Slider)]
public void VerifySliderColors()
{
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/Core/src/Handlers/Slider/SliderHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public static void MapThumbImageSource(ISliderHandler handler, ISlider slider)
}
}

internal static void MapBackgroundColor(ISliderHandler handler, ISlider slider)
{
if (handler.PlatformView is MauiSlider mauiSlider)
{
mauiSlider.UpdateBackgroundColor(slider);
}
}

void OnPlatformViewLoaded(object sender, RoutedEventArgs e)
{
var platformView = sender as Slider;
Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/Handlers/Slider/SliderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class SliderHandler : ISliderHandler
[nameof(ISlider.ThumbColor)] = MapThumbColor,
[nameof(ISlider.ThumbImageSource)] = MapThumbImageSource,
[nameof(ISlider.Value)] = MapValue,
#if WINDOWS
[nameof(ISlider.Background)] = MapBackgroundColor
#endif
};

public static CommandMapper<ISlider, ISliderHandler> CommandMapper = new(ViewCommandMapper)
Expand Down
64 changes: 39 additions & 25 deletions src/Core/src/Platform/Windows/SliderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Media;

namespace Microsoft.Maui.Platform
{
Expand All @@ -19,7 +20,9 @@ static void UpdateIncrement(this Slider nativeSlider, ISlider slider)

// Setting the Slider SmallChange property to 0 would throw an System.ArgumentException.
if (difference != 0)
{
stepping = Math.Min((difference) / 1000, 1);
}

nativeSlider.StepFrequency = stepping;
}
Expand All @@ -39,19 +42,14 @@ public static void UpdateMaximum(this Slider nativeSlider, ISlider slider)
public static void UpdateValue(this Slider nativeSlider, ISlider slider)
{
if (nativeSlider.Value != slider.Value)
{
nativeSlider.Value = slider.Value;
}
}

public static void UpdateMinimumTrackColor(this Slider platformSlider, ISlider slider)
{
var brush = slider.MinimumTrackColor?.ToPlatform();

if (brush is null)
platformSlider.Resources.RemoveKeys(MinimumTrackColorResourceKeys);
else
platformSlider.Resources.SetValueForAllKey(MinimumTrackColorResourceKeys, brush);

platformSlider.RefreshThemeResources();
UpdateColor(platformSlider, MinimumTrackColorResourceKeys, slider.MinimumTrackColor?.ToPlatform());
}

static readonly string[] MinimumTrackColorResourceKeys =
Expand All @@ -64,14 +62,7 @@ public static void UpdateMinimumTrackColor(this Slider platformSlider, ISlider s

public static void UpdateMaximumTrackColor(this Slider platformSlider, ISlider slider)
{
var brush = slider.MaximumTrackColor?.ToPlatform();

if (brush == null)
platformSlider.Resources.RemoveKeys(MaximumTrackColorResourceKeys);
else
platformSlider.Resources.SetValueForAllKey(MaximumTrackColorResourceKeys, brush);

platformSlider.RefreshThemeResources();
UpdateColor(platformSlider, MaximumTrackColorResourceKeys, slider.MaximumTrackColor?.ToPlatform());
}

static readonly string[] MaximumTrackColorResourceKeys =
Expand All @@ -84,14 +75,7 @@ public static void UpdateMaximumTrackColor(this Slider platformSlider, ISlider s

public static void UpdateThumbColor(this Slider platformSlider, ISlider slider)
{
var brush = slider.ThumbColor?.ToPlatform();

if (brush is null)
platformSlider.Resources.RemoveKeys(ThumbColorResourceKeys);
else
platformSlider.Resources.SetValueForAllKey(ThumbColorResourceKeys, brush);

platformSlider.RefreshThemeResources();
UpdateColor(platformSlider, ThumbColorResourceKeys, slider.ThumbColor?.ToPlatform());
}

static readonly string[] ThumbColorResourceKeys =
Expand Down Expand Up @@ -144,13 +128,43 @@ void OnImageOpened(object sender, RoutedEventArgs e)
}

if (nativeSlider.Parent is FrameworkElement frameworkElement)
{
frameworkElement.InvalidateMeasure();
}
}
;
}

nativeSlider.ThumbImageSource = nativeThumbImageSource?.Value;
}
}

static readonly string[] BackgroundColorResourceKeys =
{
"SliderContainerBackground",
"SliderContainerBackgroundPointerOver",
"SliderContainerBackgroundPressed",
"SliderContainerBackgroundDisabled",
};

internal static void UpdateBackgroundColor(this MauiSlider platformSlider, ISlider slider)
{
UpdateColor(platformSlider, BackgroundColorResourceKeys, slider.Background?.ToPlatform());
}

static void UpdateColor(Slider platformSlider, string[] keys, Brush? brush)
{
ResourceDictionary resource = platformSlider.Resources;

if (brush is null)
{
resource.RemoveKeys(keys);
}
else
{
resource.SetValueForAllKey(keys, brush);
}

platformSlider.RefreshThemeResources();
}
}
}
Loading