-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentryhandler.html
More file actions
284 lines (250 loc) · 11 KB
/
Copy pathentryhandler.html
File metadata and controls
284 lines (250 loc) · 11 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html class="wide wow-animation" lang="en">
<head>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8026277731801765"
crossorigin="anonymous"></script>
<!-- Site Title-->
<title>Entry Handler</title>
<meta content=".NET MAUI controls are rendered via handlers, which are lightweight classes that map appearance, properties, and behavior to native implementations."
name="description">
<meta content="Entry Handler"
name="keywords">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<!-- Stylesheets-->
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css2?family=Libre+Franklin:ital,wght@0,200;0,300;0,500;0,600;1,300&display=swap">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="page-loader">
<div class="cssload-container">
<div class="cssload-speeding-wheel"></div>
</div>
</div>
<!-- Page-->
<div class="page">
<!-- Page header-->
<header class="page-header">
<!-- RD Navbar-->
<div class="rd-navbar-wrap">
<nav class="rd-navbar novi-bg novi-bg-img" data-layout="rd-navbar-fixed" data-sm-layout="rd-navbar-fixed" data-md-layout="rd-navbar-fixed" data-lg-layout="rd-navbar-fixed" data-xl-layout="rd-navbar-static" data-xxl-layout="rd-navbar-static" data-sm-device-layout="rd-navbar-fixed" data-md-device-layout="rd-navbar-fixed" data-lg-device-layout="rd-navbar-fixed" data-xl-device-layout="rd-navbar-static" data-xxl-device-layout="rd-navbar-static" data-stick-up-clone="false" data-sm-stick-up="true" data-md-stick-up="true" data-lg-stick-up="true" data-xl-stick-up="true" data-xxl-stick-up="true" data-lg-stick-up-offset="69px" data-xl-stick-up-offset="1px" data-xxl-stick-up-offset="1px">
<div class="rd-navbar-inner">
<!-- RD Navbar Panel-->
<div class="rd-navbar-panel">
<button class="rd-navbar-toggle" data-rd-navbar-toggle=".rd-navbar-nav-wrap"><span></span></button>
<!-- RD Navbar Brand-->
<div class="rd-navbar-brand">
<!-- Brand-->
<!--
<a class="brand" href="index.html"><img class="brand-logo-dark" src="images/logo-default-347x65.png" alt="" width="173" height="32" /><img class="brand-logo-light" src="images/logo-inverse-347x65.png" alt="" width="173" height="32" /></a>
-->
<div><a href="index.html" style="color:black;margin-top:2.5px;font-size:22px;">MAUIMAN.dev</a></div>
</div>
</div>
<!-- RD Navbar Nav-->
<div class="rd-navbar-nav-wrap">
<ul class="rd-navbar-nav">
<li><a href="index.html">Home</a></li>
<!--
<li class="active"><a href="index.html#articles">Articles</a></li>
<li class="active"><a href="index.html#samples">Samples</a></li>
-->
<!--
<li class="active"><a href="index.html#templates">Templates</a></li>
<li class="active"><a href="index.html#components">Components</a></li>
-->
</ul>
</div>
</div>
</nav>
</div>
</header>
<!-- Breadcrumbs-->
<section class="section novi-bg novi-bg-img breadcrumbs-custom">
<div class="container">
<div class="breadcrumbs-custom__inner">
<p class="breadcrumbs-custom__title">MANual page for .NET MAUI DEVelopers</p>
<ul class="breadcrumbs-custom__path">
<li><a href="index.html">Home</a></li>
<li class="active">MAUI</li>
</ul>
</div>
</div>
</section>
<section class="section novi-bg novi-bg-img bg-default section-lg">
<div class="container">
<div class="row row-fix row-70">
<div class="col-lg-7 col-xl-8 section-divided__main group-post">
<!-- Post standard-->
<div class="section-md">
<article class="post-classic">
<div class="post-classic-title">
<h4>Entry Handler</h4>
</div>
<div class="post-classic-body">
<p>
.NET MAUI controls are rendered via handlers, which are lightweight classes that map appearance, properties, and behavior to native implementations.
Through these handlers, you can change the look and feel of the native platform control easily. The sample below illustrates how to create an Entry Handler and then used it to change its background color.
</p>
<p>
1. In your .NET MAUI Project, create a MyEntry class that inherits from Entry.
</p>
<p>
<div class="" style="border: 1px solid #969696;text-align:left;background:whitesmoke"><pre><code style="color:rgb(87, 87, 87);background:whitesmoke">
namespace entryhandler
{
public class MyEntry: Entry
{
}
}
</code></pre></div>
</p>
<p>
2. In MainPage.xaml, add a MyEntry element for entering text. An entry namespace is declared with the following:
</p>
<p>
<kbd>
xmlns:entry="clr-namespace:entryhandler"
</kbd>
</p>
<p>
With the namespace, MyEntry can be use in XAML as shown inside the StackLayout below:
</p>
<p>
<div class="" style="border: 1px solid #969696;text-align:left;background:whitesmoke"><pre><code style="color:rgb(87, 87, 87);background:whitesmoke">
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="entryhandler.MainPage"
xmlns:entry="clr-namespace:entryhandler"
BackgroundColor="{DynamicResource SecondaryColor}">
<StackLayout x:Name="MyStackLayout"
Margin="10">
<Label Text="Name" />
<entry:MyEntry
Text="MauiMan Entry Handler"/>
</StackLayout>
</ContentPage>
</code></pre></div>
</p>
<p>
3. We have defined an Entry subclass and use it in a XAML page. The aim is so that we can change the appearance of the Entry control. In App.cs, add the following:
</p>
<p>
<div class="" style="border: 1px solid #969696;text-align:left;background:whitesmoke"><pre><code style="color:rgb(87, 87, 87);background:whitesmoke">
using Microsoft.Maui.Platform;
namespace entryhandler;
public partial class App : Application
{
public App()
{
InitializeComponent();
Microsoft.Maui.Handlers.EntryHandler.EntryMapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
{
if (view is MyEntry)
{
#if ANDROID
handler.NativeView.SetBackgroundColor(Colors.LightGray.ToNative());
#elif IOS
handler.NativeView.BackgroundColor = Colors.LightGray.ToNative();
handler.NativeView.BorderStyle = UIKit.UITextBorderStyle.Line;
#elif WINDOWS
handler.NativeView.Background = Colors.LightGray.ToNative();
#endif
}
});
MainPage = new MainPage();
}
}
</code></pre></div>
</p>
<p>
<div>
<img width="50%" height="50%" src=images/entry_handler.png />
</div>
</p>
<p>
4. (Optional: Platform-Specific) You can also consider using platform-specific code for changing the appearance of a control. For example, you can modify MainActivity.cs with the following Entry Handler code:
</p>
<p>
<div class="" style="border: 1px solid #969696;text-align:left;background:whitesmoke"><pre><code style="color:rgb(87, 87, 87);background:whitesmoke">
using Microsoft.Maui;
using Microsoft.Maui.Platform;
.
.
public class MainActivity : MauiAppCompatActivity
{
public MainActivity()
{
Microsoft.Maui.Handlers.EntryHandler.EntryMapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
{
if (view is MyEntry)
{
handler.NativeView.SetBackgroundColor(Colors.LightGray.ToNative());
}
});
}
.
.
}
</code></pre></div>
</p>
<h5>Download</h5>
<p>
<ul class="list-marked">
<li><a href="./download/entryhandler.zip">entryhandler.zip</a></li>
</ul>
</p>
</div>
</article>
</div>
</div>
<div class="col-lg-5 col-xl-4 section-divided__aside section-divided__aside-left group-post">
<!-- Categories-->
<div class="section-md">
<h5>.NET MAUI</h5>
<ul class="list-linked">
<li><a href="twitter.html">#100DAYSOFCODE</a></li>
</ul>
</div>
</div>
</div>
</div>
</section>
<!-- Page Footer-->
<footer>
<!--
<div class="pre-footer-corporate novi-bg novi-bg-img">
<div class="container">
<div class="row justify-content-sm-center justify-content-lg-start row-30 row-md-60">
<div class="col-sm-10 col-md-6 col-lg-10 col-xl-3">
</div>
<div class="col-sm-10 col-md-6 col-lg-3 col-xl-3">
</div>
<div class="col-sm-10 col-md-6 col-lg-5 col-xl-3">
</div>
<div class="col-sm-10 col-md-6 col-lg-4 col-xl-3">
</div>
</div>
</div>
</div>
-->
<div class="footer-corporate novi-bg novi-bg-img">
<div class="container">
<div class="footer-corporate__inner">
<p class="rights">Copyright MAUIMAN.dev 2021-2023. All rights reserved. </p>
</div>
</div>
</div>
</footer>
</div>
<!-- Global Mailform Output-->
<div class="snackbars" id="form-output-global"></div>
<!-- Javascript-->
<script src="js/core.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>