Bug 59926 - On UWP, binding the Value property of a Slider does not result in the bound value being used
Summary: On UWP, binding the Value property of a Slider does not result in the bound v...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-03 15:31 UTC by John Hardman
Modified: 2017-10-03 16:01 UTC (History)
3 users (show)

See Also:
Tags: Slider UWP Binding
Is this bug a regression?: ---
Last known good build:


Attachments

Description John Hardman 2017-10-03 15:31:06 UTC
Using XF 2.3.4.270, use the code below and push an instance of SliderBindingBugPageView onto the navigation stack.
On Android, the Slider displayed has the value 50.0 as expected. On UWP, the Slider incorrectly has the value 1.0. It would appear that on UWP, the bound Value is being overridden by the Minimum property.


using System;
using System.ComponentModel;

using Xamarin.Forms;

namespace ViewsUsingXamarinForms
{
	public class SliderBindingBugViewModel
	{
		public event PropertyChangedEventHandler PropertyChanged = delegate { };

		private double _sliderValue = 50.0;
		public double SliderValue
		{
			get => _sliderValue;

			set
			{
				if (Math.Abs(_sliderValue - value) > 0.001)
				{
					_sliderValue = value;
					PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SliderValue)));
				}
			}
		}
	}

	public class MySlider : Slider
	{
		private const bool WorkaroundBugs43435And47805_ExceptionsBindingSlider = true;

		public MySlider(double min, double max)
		{
			Minimum = WorkaroundBugs43435And47805_ExceptionsBindingSlider ? 0.0 : min;
			Maximum = max;
			Minimum = min;
		}
	}

	public class SliderBindingBugPageView : ContentPage
	{
		private SliderBindingBugViewModel ViewModel = new SliderBindingBugViewModel();

		protected override void OnAppearing()
		{

			MySlider slider = new MySlider(1.0, 100.0)
			{
				BackgroundColor = Color.White,
				ClassId = "KCI_Slider",
				HorizontalOptions = LayoutOptions.FillAndExpand,
				InputTransparent = false,
				VerticalOptions = LayoutOptions.Start,
				AutomationId = "AID_Slider",
				BindingContext = ViewModel,
			};

			// TODO - put this in
			slider.SetBinding(
				Slider.ValueProperty,
				new Binding(
					nameof(SliderBindingBugViewModel.SliderValue),
					BindingMode.TwoWay,
					null,
					null,
					null));

			this.BackgroundColor = Color.AntiqueWhite;
			this.Content = new StackLayout
			{
				Padding = new Thickness(0, 10, 0, 10),
				VerticalOptions = LayoutOptions.Start,
				Children =
				{
					slider
				}
			};
		}

	} // public class SliderBindingBugPageView : ContentPage

} // namespace ViewsUsingXamarinForms

// eof
Comment 1 Paul DiPietro [MSFT] 2017-10-03 16:01:39 UTC
This is fixed in 2.4.0.

Note You need to log in before you can comment on or make changes to this bug.