forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormsSlider.cs
68 lines (56 loc) · 1.64 KB
/
FormsSlider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media.Imaging;
namespace Xamarin.Forms.Platform.UWP
{
public class FormsSlider : Windows.UI.Xaml.Controls.Slider
{
internal Thumb Thumb { get; set; }
internal Thumb ImageThumb { get; set; }
public static readonly DependencyProperty ThumbImageProperty =
DependencyProperty.Register(nameof(ThumbImage), typeof(BitmapImage),
typeof(FormsSlider), new PropertyMetadata(null, PropertyChangedCallback));
static void PropertyChangedCallback(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var slider = (FormsSlider)dependencyObject;
SwapThumbs(slider);
}
static void SwapThumbs(FormsSlider slider)
{
if (slider.Thumb == null || slider.ImageThumb == null)
{
return;
}
if (slider.ThumbImage != null)
{
slider.Thumb.Visibility = Visibility.Collapsed;
slider.ImageThumb.Visibility = Visibility.Visible;
}
else
{
slider.Thumb.Visibility = Visibility.Visible;
slider.ImageThumb.Visibility = Visibility.Collapsed;
}
}
public BitmapImage ThumbImage
{
get { return (BitmapImage)GetValue(ThumbImageProperty); }
set { SetValue(ThumbImageProperty, value); }
}
internal event EventHandler Ready;
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
Thumb = GetTemplateChild("HorizontalThumb") as Thumb;
ImageThumb = GetTemplateChild("HorizontalImageThumb") as Thumb;
SwapThumbs(this);
OnReady();
}
protected virtual void OnReady()
{
Ready?.Invoke(this, EventArgs.Empty);
}
}
}