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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
using System;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
namespace Xamarin.Forms.Platform.Tizen
{
public class ButtonRenderer : ViewRenderer<Button, Native.Button>
{
public ButtonRenderer()
{
RegisterPropertyHandler(Button.TextProperty, UpdateText);
RegisterPropertyHandler(Button.FontFamilyProperty, UpdateText);
RegisterPropertyHandler(Button.FontSizeProperty, UpdateText);
RegisterPropertyHandler(Button.FontAttributesProperty, UpdateText);
RegisterPropertyHandler(Button.TextColorProperty, UpdateTextColor);
RegisterPropertyHandler(Button.ImageProperty, UpdateBitmap);
RegisterPropertyHandler(Button.BorderColorProperty, UpdateBorder);
RegisterPropertyHandler(Button.BorderRadiusProperty, UpdateBorder);
RegisterPropertyHandler(Button.BorderWidthProperty, UpdateBorder);
}
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
if (Control == null)
{
var button = new Native.Button(Forms.Context.MainWindow)
{
PropagateEvents = false,
};
SetNativeControl(button);
}
if (e.OldElement != null)
{
Control.Clicked -= ButtonClickedHandler;
}
if (e.NewElement != null)
{
Control.Clicked += ButtonClickedHandler;
}
base.OnElementChanged(e);
}
protected override Size MinimumSize()
{
return Control.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
}
void ButtonClickedHandler(object sender, EventArgs e)
{
IButtonController btn = Element as IButtonController;
if (btn != null)
{
btn.SendClicked();
}
}
void UpdateText()
{
Control.Text = Element.Text ?? "";
Control.FontSize = Element.FontSize;
Control.FontAttributes = Element.FontAttributes;
Control.FontFamily = Element.FontFamily;
}
void UpdateTextColor()
{
Control.TextColor = Element.TextColor.ToNative();
}
void UpdateBitmap()
{
if (!string.IsNullOrEmpty(Element.Image))
{
Control.Image = new Native.Image(Control);
var task = Control.Image.LoadFromImageSourceAsync(Element.Image);
}
else
{
Control.Image = null;
}
}
protected override void UpdateThemeStyle()
{
Control.UpdateStyle(Specific.GetStyle(Element));
((IVisualElementController)Element).NativeSizeChanged();
}
void UpdateBorder()
{
/* The simpler way is to create some specialized theme for button in
* tizen-theme
*/
// TODO: implement border handling
}
}
}
|