blob: da00ef9f3d90159d57bd50a47a4f4b19a610adf5 (
plain)
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
|
using System;
using System.ComponentModel;
using ElmSharp;
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
namespace Xamarin.Forms.Platform.Tizen
{
public class SwitchRenderer : ViewRenderer<Switch, Check>
{
public SwitchRenderer()
{
RegisterPropertyHandler(Switch.IsToggledProperty, HandleToggled);
}
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
if (Control == null)
{
var _switch = new Check(Forms.Context.MainWindow)
{
PropagateEvents = false,
};
SetNativeControl(_switch);
}
if (e.OldElement != null)
{
Control.StateChanged -= CheckChangedHandler;
}
if (e.NewElement != null)
{
Control.StateChanged += CheckChangedHandler;
}
base.OnElementChanged(e);
}
protected override void UpdateThemeStyle()
{
var style = Specific.GetStyle(Element);
switch (style)
{
case SwitchStyle.Toggle:
case SwitchStyle.Favorite:
case SwitchStyle.CheckBox:
Control.Style = style;
break;
default:
Control.Style = SwitchStyle.Toggle;
break;
}
((IVisualElementController)Element).NativeSizeChanged();
}
void CheckChangedHandler(object sender, EventArgs e)
{
Element.SetValue(Switch.IsToggledProperty, Control.IsChecked);
}
void HandleToggled()
{
Control.IsChecked = Element.IsToggled;
}
}
}
|