From e3114cedb5b9a59b7bd83c9e2c11197db943806d Mon Sep 17 00:00:00 2001 From: Elisha Sam Peter Prabhu Date: Tue, 12 Sep 2023 17:45:17 +0530 Subject: [PATCH 1/2] Modify Slider labels Update Alternate labels Add TickValue property --- DemoApp/DemoApp/Views/SliderSamplePage.xaml | 2 ++ .../Controls/TMSlider/SliderCore.cs | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/DemoApp/DemoApp/Views/SliderSamplePage.xaml b/DemoApp/DemoApp/Views/SliderSamplePage.xaml index a022b674..a8416cc7 100644 --- a/DemoApp/DemoApp/Views/SliderSamplePage.xaml +++ b/DemoApp/DemoApp/Views/SliderSamplePage.xaml @@ -37,6 +37,7 @@ ShowToolTip="{Binding ShowTooltip}" IsEnabled="{Binding IsEnabled}" StepValue="1" + TickValue="15" RightIconSource="placeholder.png" LeftIconSource="placeholder.png" Padding="0,15" /> @@ -47,6 +48,7 @@ ShowToolTip="{Binding ShowTooltip}" IsEnabled="{Binding IsEnabled}" StepValue="1" + TickValue="1" RightIconSource="placeholder.png" LeftIconSource="placeholder.png" Padding="0,15" /> diff --git a/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs b/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs index 32488ee8..f45a7772 100644 --- a/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs +++ b/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs @@ -26,6 +26,7 @@ public abstract class SliderCore : Grid public static BindableProperty MinimumValueProperty = BindableProperty.Create(nameof(MinimumValue), typeof(double), typeof(SliderCore), .0, propertyChanged: OnMinimumMaximumValuePropertyChanged); public static BindableProperty MaximumValueProperty = BindableProperty.Create(nameof(MaximumValue), typeof(double), typeof(SliderCore), 1.0, propertyChanged: OnMinimumMaximumValuePropertyChanged); public static BindableProperty StepValueProperty = BindableProperty.Create(nameof(StepValue), typeof(double), typeof(SliderCore), 0.01, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnMinimumMaximumValuePropertyChanged); + public static BindableProperty TickValueProperty = BindableProperty.Create(nameof(TickValue), typeof(double), typeof(SliderCore), 10.0, defaultBindingMode: BindingMode.TwoWay); public static BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(SliderSize), typeof(SliderCore), SliderSize.Medium, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnLayoutPropertyChanged); public static BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(SliderCore), null, propertyChanged: OnTitleTextPropertyChanged); public static BindableProperty LeftTextProperty = BindableProperty.Create(nameof(LeftText), typeof(string), typeof(SliderCore), null); @@ -111,6 +112,11 @@ public double StepValue get => (double)GetValue(StepValueProperty); set => SetValue(StepValueProperty, value); } + public double TickValue + { + get => (double)GetValue(TickValueProperty); + set => SetValue(TickValueProperty, value); + } #endregion #region UI Elements @@ -181,6 +187,7 @@ public double StepValue }; internal AbsoluteLayout SliderContainer = new AbsoluteLayout(); internal StackLayout SliderHolderLayout = new StackLayout(); + private bool alternateValue = true; #endregion #region Constructor @@ -292,15 +299,19 @@ protected void BuildStepper() StepContainer.Children.Clear(); StepContainer.WidthRequest = SliderContainer.Width - _thumbSize; - for (var i = MinimumValue; StepValue != 0 && i < MaximumValue; i += StepValue) + for (var i = MinimumValue; TickValue != 0 && i < MaximumValue; i += (MaximumValue - MinimumValue) / TickValue) { var stack = SliderHelper.CreateStepLabelContainer(); var box = SliderHelper.CreateStepLine(Size); stack.Children.Add(box); - var label = SliderHelper.CreateStepLabel(Size); - label.Text = i.ToString(); - stack.Children.Add(label); + if (!alternateValue) + { + var label = SliderHelper.CreateStepLabel(Size); + label.Text = Math.Round(i, 2).ToString(); + stack.Children.Add(label); + } + alternateValue = !alternateValue; StepContainer.Children.Add(stack); } } From e150accdfde6c75c90e74a9e58618ba5fa299510 Mon Sep 17 00:00:00 2001 From: Elisha Sam Peter Prabhu Date: Wed, 13 Sep 2023 11:47:44 +0530 Subject: [PATCH 2/2] Add Coerce Value,Update alignment --- DemoApp/DemoApp/Views/SliderSamplePage.xaml | 2 +- .../Controls/TMSlider/SliderCore.cs | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/DemoApp/DemoApp/Views/SliderSamplePage.xaml b/DemoApp/DemoApp/Views/SliderSamplePage.xaml index a8416cc7..3b2acd5f 100644 --- a/DemoApp/DemoApp/Views/SliderSamplePage.xaml +++ b/DemoApp/DemoApp/Views/SliderSamplePage.xaml @@ -37,7 +37,7 @@ ShowToolTip="{Binding ShowTooltip}" IsEnabled="{Binding IsEnabled}" StepValue="1" - TickValue="15" + TickValue="10" RightIconSource="placeholder.png" LeftIconSource="placeholder.png" Padding="0,15" /> diff --git a/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs b/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs index f45a7772..7fe03061 100644 --- a/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs +++ b/Trimble.Modus.Components/Controls/TMSlider/SliderCore.cs @@ -23,10 +23,10 @@ public abstract class SliderCore : Grid #endregion #region Bindable Property - public static BindableProperty MinimumValueProperty = BindableProperty.Create(nameof(MinimumValue), typeof(double), typeof(SliderCore), .0, propertyChanged: OnMinimumMaximumValuePropertyChanged); + public static BindableProperty MinimumValueProperty = BindableProperty.Create(nameof(MinimumValue), typeof(double), typeof(SliderCore), .0, propertyChanged: OnMinimumMaximumValuePropertyChanged); public static BindableProperty MaximumValueProperty = BindableProperty.Create(nameof(MaximumValue), typeof(double), typeof(SliderCore), 1.0, propertyChanged: OnMinimumMaximumValuePropertyChanged); public static BindableProperty StepValueProperty = BindableProperty.Create(nameof(StepValue), typeof(double), typeof(SliderCore), 0.01, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnMinimumMaximumValuePropertyChanged); - public static BindableProperty TickValueProperty = BindableProperty.Create(nameof(TickValue), typeof(double), typeof(SliderCore), 10.0, defaultBindingMode: BindingMode.TwoWay); + public static BindableProperty TickValueProperty = BindableProperty.Create(nameof(TickValue), typeof(double), typeof(SliderCore), 10.0, defaultBindingMode: BindingMode.TwoWay, coerceValue: TickCoerceValue); public static BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(SliderSize), typeof(SliderCore), SliderSize.Medium, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnLayoutPropertyChanged); public static BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(SliderCore), null, propertyChanged: OnTitleTextPropertyChanged); public static BindableProperty LeftTextProperty = BindableProperty.Create(nameof(LeftText), typeof(string), typeof(SliderCore), null); @@ -34,12 +34,12 @@ public abstract class SliderCore : Grid public static BindableProperty LeftIconProperty = BindableProperty.Create(nameof(LeftIconSource), typeof(ImageSource), typeof(SliderCore), null, propertyChanged: OnLeftIconSourceChanged); public static BindableProperty RightIconProperty = BindableProperty.Create(nameof(RightIconSource), typeof(ImageSource), typeof(SliderCore), null, propertyChanged: OnRightIconSourceChanged); public static BindableProperty ShowStepsProperty = BindableProperty.Create(nameof(ShowSteps), typeof(Boolean), typeof(SliderCore), false, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnShowStepsPropertyChanged); - public static BindableProperty ShowToolTipProperty= BindableProperty.Create(nameof(ShowToolTip), typeof(Boolean), typeof(SliderCore), false, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnShowToolTipPropertyChanged); + public static BindableProperty ShowToolTipProperty = BindableProperty.Create(nameof(ShowToolTip), typeof(Boolean), typeof(SliderCore), false, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnShowToolTipPropertyChanged); #endregion #region Property change methods static void OnTitleTextPropertyChanged(BindableObject bindable, object oldValue, object newValue) - => ((SliderCore)bindable).OnTitleTextPropertyChanged((string) newValue); + => ((SliderCore)bindable).OnTitleTextPropertyChanged((string)newValue); static void OnShowStepsPropertyChanged(BindableObject bindable, object oldValue, object newValue) => ((SliderCore)bindable).OnShowStepsPropertyChanged(); static void OnShowToolTipPropertyChanged(BindableObject bindable, object oldValue, object newValue) @@ -303,6 +303,7 @@ protected void BuildStepper() { var stack = SliderHelper.CreateStepLabelContainer(); var box = SliderHelper.CreateStepLine(Size); + box.VerticalOptions = LayoutOptions.Start; stack.Children.Add(box); if (!alternateValue) @@ -395,5 +396,28 @@ protected void SetValueLabelBinding(Label label, BindableProperty bindableProper /// protected abstract void OnTitleTextPropertyChanged(string newValue); #endregion + #region Private Methods + private static object TickCoerceValue(BindableObject bindable, object value) + { + var slider = (bindable as TMSlider); + return CoerceValue((double)value); + + } + private static object CoerceValue(double value) + { + if (value < 1 && value > 0) + { + return 1; + } + if (value > 50) + { + return 50; + } + else + { + return 0; + } + } + #endregion } }