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
@@ -362,18 +362,32 @@ public class MyViewModel : IBindingContext
362
362
363
363
#### Wrapping a non-observable model
364
364
365
-
A common scenario, for instance, when working with collection items, is to create a wrapping "bindable" item model that relays properties of the collection item model, and raises the property value changed notifications when needed.
365
+
A common scenario, for instance, when working with database items, is to create a wrapping "bindable" model that relays properties of the database model, and raises the property changed notifications when needed.
@@ -384,29 +398,41 @@ public class ItemViewModel : IBindingContext
384
398
</ui:UXML>
385
399
```
386
400
387
-
The `ItemViewModel` can be serialized and deserialized without any issues.
388
-
389
401
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).
Waiting for the [partial properties](https://github.com/dotnet/csharplang/issues/6420) support to make it even shorter.
420
446
421
447
```csharp
422
-
publicpartialclassItemViewModel : IBindingContext
448
+
publicpartialclassUserViewModel : IBindingContext
423
449
{
450
+
privatereadonlyUser_user;
451
+
452
+
publicUserViewModel(Useruser)
453
+
{
454
+
_user=user;
455
+
_name.Value=user.Name;
456
+
}
457
+
424
458
[WithObservableBackingField]
425
459
publicpartialstringName { get; set; }
426
460
}
427
461
```
428
462
429
463
> **Note:** The [UnityMvvmToolkit.Generator](https://github.com/LibraStack/UnityMvvmToolkit.Generator) is available exclusively for my [patrons](https://patreon.com/DimaChebanov).
430
464
465
+
#### Serializable ViewModel
466
+
467
+
A common scenario, for instance, when working with collection items, is to create a "bindable" item that can be serialized.
The `ItemViewModel` can be serialized and deserialized without any issues.
492
+
493
+
The same result, but 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).
526
+
431
527
### Command & Command\<T\>
432
528
433
529
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.
@@ -731,6 +827,7 @@ Once the `UnityMVVMToolkit` is installed, create a class `MyFirstViewModel` that
731
827
732
828
```csharp
733
829
usingUnityMvvmToolkit.Core;
830
+
usingUnityMvvmToolkit.Core.Interfaces;
734
831
735
832
publicclassMyFirstViewModel : IBindingContext
736
833
{
@@ -870,7 +967,7 @@ public class TextFieldViewModel : IBindingContext
0 commit comments