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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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.