blob: bba9d260b267a64390bf2e283a064baff8b376c7 (
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
|
using System.ComponentModel;
using Android.Content;
using Android.Views;
using AView = Android.Views.View;
using ASwitch = Android.Widget.Switch;
namespace Xamarin.Forms.Platform.Android
{
public class SwitchCellRenderer : CellRenderer
{
const double DefaultHeight = 30;
SwitchCellView _view;
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
{
var cell = (SwitchCell)Cell;
if ((_view = convertView as SwitchCellView) == null)
_view = new SwitchCellView(context, item);
_view.Cell = cell;
UpdateText();
UpdateChecked();
UpdateHeight();
return _view;
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == SwitchCell.TextProperty.PropertyName)
UpdateText();
else if (args.PropertyName == SwitchCell.OnProperty.PropertyName)
UpdateChecked();
else if (args.PropertyName == "RenderHeight")
UpdateHeight();
}
void UpdateChecked()
{
((ASwitch)_view.AccessoryView).Checked = ((SwitchCell)Cell).On;
}
void UpdateHeight()
{
_view.SetRenderHeight(Cell.RenderHeight);
}
void UpdateText()
{
_view.MainText = ((SwitchCell)Cell).Text;
}
}
}
|