-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ToolbarItems.cs
111 lines (96 loc) · 2.48 KB
/
ToolbarItems.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
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
99
100
101
102
103
104
105
106
107
108
109
using System;
using Xamarin.Forms;
namespace Xamarin.Forms.Controls
{
public class ToolbarItems : ContentPage
{
bool _isEnable = false;
public ToolbarItems()
{
var label = new Label { Text = "Hello ContentPage", AutomationId = "label_id" };
var command = new Command((obj) =>
{
label.Text = "button 4 new text";
}, (obj) => _isEnable);
var tb1 = new ToolbarItem("tb1", "menuIcon.png", () =>
{
label.Text = "tb1";
}, ToolbarItemOrder.Primary);
tb1.IsEnabled = _isEnable;
tb1.AutomationId = "toolbaritem_primary";
var fis = new FontImageSource()
{
FontFamily = GetFontFamily(),
Glyph = '\uf101'.ToString(),
Color = Color.Red
};
var tb2 = new ToolbarItem("tb2 font", null, () =>
{
label.Text = "tb2";
}, ToolbarItemOrder.Primary);
tb2.IconImageSource = fis;
tb2.AutomationId = "toolbaritem_primary2";
var tb6 = new ToolbarItem("tb6 long long text", null, () =>
{
label.Text = "tb6";
}, ToolbarItemOrder.Primary);
tb6.AutomationId = "toolbaritem_primary6";
var tb3 = new ToolbarItem("tb3", "bank.png", () =>
{
label.Text = "tb3";
_isEnable = !_isEnable;
command.ChangeCanExecute();
}, ToolbarItemOrder.Secondary);
tb3.AutomationId = "toolbaritem_secondary";
var tb4 = new ToolbarItem();
tb4.Text = "tb4";
tb4.Order = ToolbarItemOrder.Secondary;
tb4.Command = command;
tb4.IconImageSource = "coffee";
tb4.AutomationId = "toolbaritem_secondary2";
var tb5 = new ToolbarItem();
tb5.Text = "tb5";
tb5.IconImageSource = "bank.png";
tb5.Order = ToolbarItemOrder.Secondary;
tb5.Command = new Command(async () => {
await Navigation.PushAsync(new ToolbarItems());
});
tb5.AutomationId = "toolbaritem_secondary5";
ToolbarItems.Add(tb1);
ToolbarItems.Add(tb2);
ToolbarItems.Add(tb3);
ToolbarItems.Add(tb4);
ToolbarItems.Add(tb5);
ToolbarItems.Add(tb6);
Content = new StackLayout
{
Children = {
label
}
};
}
static string GetFontFamily()
{
var fontFamily = "";
switch (Device.RuntimePlatform)
{
case Device.macOS:
case Device.iOS:
fontFamily = "Ionicons";
break;
case Device.UWP:
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
break;
case Device.WPF:
case Device.GTK:
fontFamily = "Assets/ionicons.ttf#ionicons";
break;
case Device.Android:
default:
fontFamily = "fonts/ionicons.ttf#";
break;
}
return fontFamily;
}
}
}