You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-12Lines changed: 82 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ FmgLib.MauiMarkup provides extension methods for all properties provided for a V
19
19
<details>
20
20
<summary><b>Getting Started<b></summary>
21
21
22
+
<br>
23
+
<br>
22
24
### Creating a new FmgLib.MauiMarkup project from CLI
23
25
24
26
FmgLib provides a project template to start a new project with FmgLib.MauiMarkup.
@@ -42,11 +44,15 @@ Install the [FmgLib.MauiMarkup](https://www.nuget.org/packages/FmgLib.MauiMarkup
42
44
```bash
43
45
dotnet add package FmgLib.MauiMarkup
44
46
```
47
+
48
+
<br>
45
49
</details>
46
50
47
51
<details>
48
52
<summary><b>XAML to FmgLib.MauiMarkup(C#)<b></summary>
49
53
54
+
<br>
55
+
<br>
50
56
If we were to write XAML code for the Image class, it would look like this:
51
57
```xaml
52
58
<Image
@@ -97,11 +103,15 @@ this
97
103
)
98
104
);
99
105
```
106
+
107
+
<br>
100
108
</details>
101
109
102
110
<details>
103
111
<summary><b>How to assign object references<b></summary>
104
112
113
+
<br>
114
+
<br>
105
115
There are two main ways to assign objects in `FmgLib.MauiMarkup`:
106
116
107
117
- using the `Assign` method,
@@ -120,11 +130,15 @@ Button btnOk;
120
130
newButton()
121
131
.Assign(outbtnOk);
122
132
```
133
+
134
+
<br>
123
135
</details>
124
136
125
137
<details>
126
138
<summary><b>Attached properties<b></summary>
127
139
140
+
<br>
141
+
<br>
128
142
Attached properties are properties that are defined on a type but are intended to be used with instances of other types. In `FmgLib.MauiMarkup`, attached properties are matched with attached property fluent methods, allowing you to set their values in a more readable and fluent manner.
129
143
130
144
For example, if you want to set the `AbsoluteLayout.LayoutBounds` attached property on a Border object, you would create an instance of Border and then use the `AbsoluteLayoutBounds` fluent method to set its value, like this:
@@ -199,6 +213,8 @@ This would set the `AbsoluteLayout.LayoutBounds` attached property to the specif
199
213
<details>
200
214
<summary><b>Behaviors<b></summary>
201
215
216
+
<br>
217
+
<br>
202
218
In `FmgLib.MauiMarkup`, you can add functionality to user interface controls using behaviors. Behaviors allow you to add functionality to controls without having to subclass them.
203
219
204
220
You can add a behavior to a control by using the `Behaviors` method and passing in an instance of the behavior class. For example:
@@ -207,10 +223,14 @@ You can add a behavior to a control by using the `Behaviors` method and passing
207
223
newEntry().Text("Click Item")
208
224
.Behaviors(newYourCustomBehaviors());
209
225
```
226
+
227
+
<br>
210
228
</details>
211
229
<details>
212
230
<summary><b>Binding Converters<b></summary>
213
231
232
+
<br>
233
+
<br>
214
234
This code is an example of how to use binding converters in `FmgLib.MauiMarkup`.
215
235
216
236
A `CollectionView` is defined and for each item in the `MyNumbers` list, a label is created with text equal to the value of the item. The `BackgroundColor` property of the label is bound to the item using the `Convert` method, which takes in a function that converts the value of the item (an integer) to a color. In this case, the function checks if the number is even or odd, and returns either `Colors.Green` or `Colors.Yellow` based on the result.
@@ -243,11 +263,15 @@ public class CustomPage : ContentPage
243
263
}
244
264
}
245
265
```
266
+
267
+
<br>
246
268
</details>
247
269
248
270
<details>
249
271
<summary><b>Event handlers<b></summary>
250
272
273
+
<br>
274
+
<br>
251
275
In Maui, you can add functionality to user interface controls by handling events. For each `EventHandler` in a `FmgLib.MauiMarkup` class, a fluent helper method is generated to make it easier to attach an event handler to the control.
252
276
253
277
For example, in the case of the `Clicked` event handler in the `Button` class, two fluent methods are generated:
@@ -300,11 +324,15 @@ new Button()
300
324
```
301
325
302
326
This makes it easy to attach event handlers to controls in a concise and readable way.
327
+
328
+
<br>
303
329
</details>
304
330
305
331
<details>
306
332
<summary><b>Gesture Recognizers<b></summary>
307
333
334
+
<br>
335
+
<br>
308
336
The following gesture recognizers are available:
309
337
310
338
-`TapGestureRecognizer`
@@ -429,11 +457,15 @@ public class PointerGesturePage : ContentPage
The `Grid` elementallowsyoutocreatecomplex, multi-rowandmulti-columnlayoutusing Row and Column definitions. You can define the number and size of the rows and columns using the `RowDefinitions` and `ColumnDefinitions` methods, respectively.
469
504
470
505
You can set the position of a child element within the grid using the `Row()`, `Column()`, `ColumnSpan()`, and `RowSpan()` methods. Thesemethodsmatchtheattachedproperties `Grid.Row`, `Grid.Column`, `Grid.ColumnSpan`, and `Grid.RowSpan`, respectively.
`FmgLib.MauiMarkup` providesaconvenientwaytosetpropertiesfor UI elements by matching properties with fluent helper methods. This makes it easier and more readable to define the interface of your application.
702
744
703
745
Here is an example of using fluent methods to set properties on a `Label`:
`FmgLib.MauiMarkup` providesasimplewaytobindpropertiesofanelementtoasource, sothatwhenthesourcechanges, thepropertychangesaswell. Youcanbindapropertybyusing the fluent method e.g. `Text()`, `TextColor()` etc. andthenusing lambda call the method `Path()` tospecifythepropertyyouwanttobindto.
729
774
730
775
@@ -754,11 +799,14 @@ In this example, the text property of the label is bound to the `Value` property
754
799
755
800
Youcanalsobindapropertytoanobjectthatisnotpartofthevisualtree. Thisisuseful when you have a separate data source, such as a model or a view model, that you want to bind to a visual element.
@@ -1224,12 +1285,14 @@ public partial class ExamplePage : ContentPage, IFmgLibHotReload
1224
1285
}
1225
1286
```
1226
1287
1288
+
<br>
1227
1289
</details>
1228
1290
1229
1291
<details>
1230
1292
<summary><b>Extensionsfor 3rd Party Controls<b></summary>
1231
-
1232
-
1293
+
1294
+
<br>
1295
+
<br>
1233
1296
FmgLib.MauiMarkup library can also generate extension methods for controls from third-party libraries. To achieve this, you should utilize the `MauiMarkupAttribute` provided by FmgLib.MauiMarkup.
1234
1297
1235
1298
Simply specify the control for which you want to create extension methods as `[MauiMarkup(typeof(YourControl))]`.
0 commit comments