Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stepper doesn't change increment value when being bound to a double in MVVM context (Windows) #24396

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Microsoft.Maui.Controls;

public class Stepper.Android
{
internal static void MapInterval(IStepperHandler handler, IStepper view)
{
handler.PlatformView.UpdateIncrement(view);
}
}
10 changes: 10 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Mapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Microsoft.Maui.Controls;
public partial class Stepper
{
internal static new void RemapForControls()
{
StepperHandler.Mapper.AppendToMapping(nameof(Stepper.Increment), Stepper.MapInterval);
}
}
8 changes: 8 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Standard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Microsoft.Maui.Controls;

public partial class Stepper
{
internal static void MapInterval(IStepperHandler handler, IStepper view){}
}
11 changes: 11 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Tizen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Microsoft.Maui.Controls;

public partial class Stepper
{
internal static void MapInterval(IStepperHandler handler, IStepper view)
{
handler.PlatformView.UpdateIncrement(view);
}
}
11 changes: 11 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Microsoft.Maui.Controls;

public partial class Stepper
{
internal static void MapInterval(IStepperHandler handler, IStepper view)
{
handler.PlatformView.UpdateInterval(view);
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Stepper/Stepper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public partial class Stepper : View, IElementConfiguration<Stepper>, IStepper
//'-log10(increment) + 4' as rounding digits gives us 4 significant decimal digits after the most significant one.
//If your increment uses more than 4 significant digits, you're holding it wrong.
/// <summary>Bindable property for <see cref="Increment"/>.</summary>
public static readonly BindableProperty IncrementProperty = BindableProperty.Create(nameof(Increment), typeof(double), typeof(Stepper), 1.0,
public static readonly BindableProperty IncrementProperty = BindableProperty.Create(nameof(Increment), typeof(double), typeof(Stepper), 1.0,
propertyChanged: (b, o, n) => { ((Stepper)b).digits = (int)(-Math.Log10((double)n) + 4).Clamp(1, 15); });

readonly Lazy<PlatformConfigurationRegistry<Stepper>> _platformConfigurationRegistry;
Expand Down
11 changes: 11 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.iOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Microsoft.Maui.Controls;

public class Stepper.iOS
{
internal static void MapInterval(IStepperHandler handler, IStepper view)
{
handler.PlatformView.UpdateIncrement(view);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20706.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue20706"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">
<ContentPage.BindingContext>
<local:ViewModelClass/>
</ContentPage.BindingContext>
<ContentPage.Content>
<VerticalStackLayout>
<Stepper AutomationId="myStepper" x:Name="stepperValue"
Maximum="1000"
Increment="{Binding Increment}" />
<Entry AutomationId="entry"
Text="{Binding Value,Source={x:Reference stepperValue}} "/>
<Button AutomationId="incrementButton" Text="Change Increment Value" x:Name="button" Clicked="button_Clicked"/>
</VerticalStackLayout>
</ContentPage.Content>
</ContentPage>
51 changes: 51 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20706.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.ComponentModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 20706, "Stepper doesn't change increment value when being bound to a double in MVVM context (Windows)", PlatformAffected.UWP)]
public partial class Issue20706 : ContentPage
{
public Issue20706 ()
{
InitializeComponent ();
}

private void button_Clicked(object sender, EventArgs e)
{
stepperValue.Increment = 10;
}
}

internal class ViewModelClass : INotifyPropertyChanged
{
private double _increment;

public double Increment
{
get
{
return _increment;
}

set
{
_increment = value;
OnPropertyChanged("Increment");
}
}

public ViewModelClass()
{
Increment = 2;
}
private void OnPropertyChanged(string v)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(v));
}
}

public event PropertyChangedEventHandler PropertyChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue20706 : _IssuesUITest
{
public override string Issue => "Stepper doesn't change increment value when being bound to a double in MVVM context (Windows)";
public Issue20706(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Stepper)]
public void ChangeIncrementValue()
{
App.WaitForElement("incrementButton");
App.IncreaseStepper("myStepper");
App.Click("incrementButton");
App.IncreaseStepper("myStepper");
App.DecreaseStepper("myStepper");
VerifyScreenshot();
}
}
}
#endif
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