/// <summary>Bindable property of ThumbColor</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Scrollbar), null,
- propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).thumbView.BackgroundColor = (Color)newValue,
- defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbView.BackgroundColor
+ propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbColor((Color)newValue),
+ defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbColor
);
/// <summary>Bindable property of TrackPadding</summary>
defaultValueCreator: (bindable) => ((Scrollbar)bindable).trackPadding
);
+ /// <summary>Bindable property of ThumbVerticalImageUrl</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty ThumbVerticalImageUrlProperty = BindableProperty.Create(nameof(ThumbVerticalImageUrl), typeof(string), typeof(Scrollbar), null,
+ propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbImage((string)newValue, false),
+ defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbVerticalImageUrl
+ );
+
+ /// <summary>Bindable property of ThumbHorizontalImageUrl</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty ThumbHorizontalImageUrlProperty = BindableProperty.Create(nameof(ThumbHorizontalImageUrl), typeof(string), typeof(Scrollbar), null,
+ propertyChanged: (bindable, oldValue, newValue) => ((Scrollbar)bindable).UpdateThumbImage((string)newValue, true),
+ defaultValueCreator: (bindable) => ((Scrollbar)bindable).thumbHorizontalImageUrl
+ );
+
+
private View trackView;
- private View thumbView;
+ private ImageView thumbView;
private Animation thumbPositionAnimation;
private Animation thumbSizeAnimation;
private Animation opacityAnimation;
private float previousPosition;
private float trackThickness = 6.0f;
private float thumbThickness = 6.0f;
+ private string thumbVerticalImageUrl;
+ private string thumbHorizontalImageUrl;
+ private Color thumbColor;
private PaddingType trackPadding = new PaddingType(4, 4, 4, 4);
+ private bool isHorizontal;
#endregion Fields
set => SetValue(TrackPaddingProperty, value);
}
+ /// <summary>
+ /// The image url of the vertical thumb.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string ThumbVerticalImageUrl
+ {
+ get => (string)GetValue(ThumbVerticalImageUrlProperty);
+ set => SetValue(ThumbVerticalImageUrlProperty, value);
+ }
+
+ /// <summary>
+ /// The image url of the horizontal thumb.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string ThumbHorizontalImageUrl
+ {
+ get => (string)GetValue(ThumbHorizontalImageUrlProperty);
+ set => SetValue(ThumbHorizontalImageUrlProperty, value);
+ }
+
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override float ScrollPosition
};
Add(trackView);
- thumbView = new View()
+ thumbView = new ImageView()
{
PositionUsesPivotPoint = true,
BackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f)
[EditorBrowsable(EditorBrowsableState.Never)]
public override void Initialize(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false)
{
+ this.isHorizontal = isHorizontal;
if (isHorizontal)
{
calculator = new HorizontalCalculator(contentLength > 0.0f ? contentLength : 0.0f, viewportLength, currentPosition);
thumbView.Size = calculator.CalculateThumbSize(ThumbThickness, trackView.Size);
thumbView.Position = calculator.CalculateThumbPaddingPosition(trackView.Size, thumbView.Size, thumbView.Position, trackPadding);
}
+ private void UpdateThumbColor(Color color)
+ {
+ thumbColor = color;
+ if (thumbView.ResourceUrl != "")
+ {
+ thumbView.Color = color;
+ thumbView.BackgroundColor = Color.Transparent;
+ }
+ else
+ {
+ thumbView.BackgroundColor = color;
+ }
+ }
+
+ private void UpdateThumbImage(string url, bool isHorizontal)
+ {
+ if (isHorizontal)
+ {
+ thumbHorizontalImageUrl = url;
+ if (this.isHorizontal)
+ {
+ thumbView.ResourceUrl = url;
+ thumbView.Color = thumbColor;
+ thumbView.BackgroundColor = Color.Transparent;
+ }
+ }
+ else
+ {
+ thumbVerticalImageUrl = url;
+ if (!this.isHorizontal)
+ {
+ thumbView.ResourceUrl = url;
+ thumbView.Color = thumbColor;
+ thumbView.BackgroundColor = Color.Transparent;
+ }
+ }
+ }
private Animation EnsureThumbPositionAnimation()
{
return ((ScrollbarStyle)bindable).trackPadding;
});
+ /// <summary>Bindable property of ThumbBackgroundImageVertical</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty ThumbVerticalImageUrlProperty = BindableProperty.Create(nameof(ThumbVerticalImageUrl), typeof(string), typeof(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ ((ScrollbarStyle)bindable).thumbVerticalImageUrl = ((string)newValue);
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ return ((ScrollbarStyle)bindable).thumbVerticalImageUrl;
+ });
+
+ /// <summary>Bindable property of ThumbBackgroundImageUrl</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty ThumbHorizontalImageUrlProperty = BindableProperty.Create(nameof(ThumbHorizontalImageUrl), typeof(string), typeof(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ ((ScrollbarStyle)bindable).thumbHorizontalImageUrl = ((string)newValue);
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ return ((ScrollbarStyle)bindable).thumbHorizontalImageUrl;
+ });
+
private float? trackThickness;
private float? thumbThickness;
private Color trackColor;
private Color thumbColor;
private Extents trackPadding;
+ private string thumbVerticalImageUrl;
+ private string thumbHorizontalImageUrl;
#endregion Fields
set => SetValue(TrackPaddingProperty, value);
}
+ /// <summary>
+ /// The image url of the vertical thumb.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string ThumbVerticalImageUrl
+ {
+ get => (string)GetValue(ThumbVerticalImageUrlProperty);
+ set => SetValue(ThumbVerticalImageUrlProperty, value);
+ }
+
+ /// <summary>
+ /// The image url of the horizontal thumb.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string ThumbHorizontalImageUrl
+ {
+ get => (string)GetValue(ThumbHorizontalImageUrlProperty);
+ set => SetValue(ThumbHorizontalImageUrlProperty, value);
+ }
+
+
#endregion Properties
}
}