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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xamarin.Forms.Controls
{
public class SearchBarGallery : ContentPage
{
Label _searchQueryLabel;
public SearchBarGallery ()
{
_searchQueryLabel = new Label {
Text = "Search Query"
};
var textChangedLabel = new Label {
Text = ""
};
var numCharsTyped = 0;
var noPlaceholder = new SearchBar();
noPlaceholder.SearchButtonPressed += OnSearchBarPressed;
noPlaceholder.TextChanged += (sender, e) => {
numCharsTyped++;
textChangedLabel.Text = numCharsTyped.ToString ();
};
var normal = new SearchBar { Placeholder = "Normal" };
normal.SearchButtonPressed += OnSearchBarPressed;
normal.TextChanged += (sender, e) => {
numCharsTyped++;
textChangedLabel.Text = numCharsTyped.ToString ();
};
var activation = new SearchBar { Placeholder = "Activation" };
activation.SearchButtonPressed += OnSearchBarPressed;
activation.TextChanged += (sender, e) => {
numCharsTyped++;
textChangedLabel.Text = numCharsTyped.ToString ();
};
var nextPageButton = new Button {
Text = "More SearchBars",
Command = new Command (async () => await Navigation.PushAsync (new SearchBarGalleryPageTwo ()))
};
int i = 1;
activation.SearchButtonPressed += (sender, e) => {
activation.Text = "";
activation.Placeholder = "Activated " + i++.ToString ();
};
Content = new ScrollView {
Content = new StackLayout {
Spacing = 0,
Children = {
noPlaceholder,
normal,
activation,
_searchQueryLabel,
textChangedLabel,
nextPageButton
}
}
};
}
void OnSearchBarPressed(object sender, EventArgs eventArgs)
{
var searchBar = (SearchBar)sender;
_searchQueryLabel.Text = searchBar.Text;
}
}
public class SearchBarGalleryPageTwo : ContentPage
{
Label _searchQueryLabel;
public SearchBarGalleryPageTwo ()
{
Title = "Search Bar Gallery Part 2";
_searchQueryLabel = new Label {
Text = "Search Query 2"
};
var disabled = new SearchBar { Placeholder = "Disabled", IsEnabled = false };
disabled.SearchButtonPressed += OnSearchBarPressed;
var transparent = new SearchBar { Placeholder = "Transparent", Opacity = 0.5 };
transparent.SearchButtonPressed += OnSearchBarPressed;
var toggleDisabledButton = new Button {
Text = "Toggle enabled",
Command = new Command (() => {
if (disabled.IsEnabled) {
disabled.IsEnabled = false;
disabled.Placeholder = "Disabled";
} else {
disabled.IsEnabled = true;
disabled.Placeholder = "Enabled";
}
})
};
Content = new ScrollView {
Content = new StackLayout {
Spacing = 0,
Children = {
disabled,
transparent,
_searchQueryLabel,
toggleDisabledButton
}
}
};
}
void OnSearchBarPressed(object sender, EventArgs eventArgs)
{
var searchBar = (SearchBar)sender;
_searchQueryLabel.Text = searchBar.Text;
}
}
}
|