I am trying to increase height of a slider in a Xamarin Forms
project using a custom renderer
for Android
. Following code works for the most part using ScaleY
.
But when I move the slider the shadow also is scaled and the thumb become invisible. Is there a way to increase the size of the slider without affecting the thumb and size of the shadow?
Custom Renderer
[assembly: ExportRenderer(typeof(MySlider), typeof(MySliderRenderer))]
namespace CustomRenderer.Android
{
public class MySliderRenderer : Xamarin.Forms.Platform.Android.SliderRenderer
{
public MySliderRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Control.ProgressDrawable.SetColorFilter(
new PorterDuffColorFilter(
Xamarin.Forms.Color.FromHex("#F50F76").ToAndroid(),
PorterDuff.Mode.SrcIn));
// Set Progress bar Thumb color
Control.Thumb.SetColorFilter(
Xamarin.Forms.Color.FromHex("#F50F76").ToAndroid(),
PorterDuff.Mode.SrcIn);
//Change height
Control.ScaleY = 10;
}
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
}
}
}
XAML
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer"
x:Class="CustomRenderer.MainPageXaml">
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Label Text="Hello, Custom Renderer 444!" />
<local:MySlider Minimum="0" Maximum="400" Value="5" />
</StackLayout>
</ContentPage>
MySlider
public class MySlider : Xamarin.Forms.Slider
{
public MySlider()
{
}
}