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
+41-9Lines changed: 41 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -386,6 +386,38 @@ public class ItemViewModel : IBindingContext
386
386
387
387
The `ItemViewModel` can be serialized and deserialized without any issues.
388
388
389
+
To achieve the same result, but with minimal boilerplate code, you can automatically create an observable backing field using the `[WithObservableBackingField]` attribute from [UnityMvvmToolkit.Generator](https://github.com/LibraStack/UnityMvvmToolkit.Generator).
> **Note:** The [UnityMvvmToolkit.Generator](https://github.com/LibraStack/UnityMvvmToolkit.Generator) is available exclusively for my [patrons](https://patreon.com/DimaChebanov).
420
+
389
421
### Command & Command\<T\>
390
422
391
423
The `Command` and `Command<T>` are `ICommand` implementations that can expose a method or delegate to the view. These types act as a way to bind commands between the viewmodel and UI elements.
@@ -1131,9 +1163,9 @@ Now we can use the `CustomViewModelProvider` as follows.
1131
1163
In this example, `Label1` and `Label2` will display the text "Main Context", while `Label3` will display the text "Custom Context".
1132
1164
1133
1165
### Source code generator
1134
-
1166
+
1135
1167
The best way to speed up the creation of custom `VisualElement` is to use source code generators. With this powerful tool, you can achieve the same great results with minimal boilerplate code and focus on what really matters: programming!
1136
-
1168
+
1137
1169
Let's create the `BindableImage` control, but this time using source code generators.
1138
1170
1139
1171
For a visual element without bindings, we will use a [UnityUxmlGenerator](https://github.com/LibraStack/UnityUxmlGenerator).
@@ -1148,12 +1180,12 @@ public partial class Image : VisualElement
1148
1180
}
1149
1181
}
1150
1182
```
1151
-
1183
+
1152
1184
<details><summary><b>Generated code</b></summary>
1153
1185
<br />
1154
1186
1155
1187
`Image.UxmlFactory.g.cs`
1156
-
1188
+
1157
1189
```csharp
1158
1190
partialclassImage
1159
1191
{
@@ -1163,9 +1195,9 @@ partial class Image
1163
1195
}
1164
1196
}
1165
1197
```
1166
-
1198
+
1167
1199
</details>
1168
-
1200
+
1169
1201
For a bindable visual element, we will use a [UnityMvvmToolkit.Generator](https://github.com/LibraStack/UnityMvvmToolkit.Generator).
1170
1202
1171
1203
```csharp
@@ -1191,12 +1223,12 @@ public partial class BindableImage : Image
As you can see, using [UnityUxmlGenerator](https://github.com/LibraStack/UnityUxmlGenerator) and [UnityMvvmToolkit.Generator](https://github.com/LibraStack/UnityMvvmToolkit.Generator) we can achieve the same results but with just a few lines of code.
0 commit comments