Guidance on Two-Way Binding on a Model property
See original GitHub issueQuestion
Hello, I am just starting out with blazor and your Mvvm library is already helping me a lot getting on. I just have a question if you could explain how to best handle two-way bindings on properties that are bound from the model. For example i have a model and a viewmodel like below. How would i go best to integrate notification into that view model?
Cheers Simon
Code sample
public class Model
{
public string Name { get; set; }
}
public class ViewModel : ViewModelBase
{
private Model _model;
public string Name
{
get => _model.Name;
set
{
_model.Name = value;
OnPropertyChanged(nameof(Name));
}
}
}
Version
6.0.3
Are you using Blazor WASM or Blazor Server?
Balzor Server
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Two-way binding
Two-way binding gives components in your application a way to share data. Use two-way binding to listen for events and update values simultaneously...
Read more >Two-way data binding
When the user changes an attribute, the method annotated using @InverseBindingAdapter is called, and the value is assigned to the backing ...
Read more >How to: Specify the Direction of the Binding - WPF .NET ...
Learn how to use the Binding.Mode property to specify whether the binding updates only the target property, the source property or both.
Read more >ngModel & Two way Data binding in Angular
Two way data binding means that changes made to our model in the component are propagated to the view and that any changes...
Read more >Two-Way Data Binding in Angular with ngModel
The two-way data binding in Angular enables data to flow from the component to the view and the other way round. It is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much for the quick response and the change. Exactly what i needed and working like a charm!
Ah I think i did not get that across correctly. I do not want the Model to notify on the ViewModel. The ViewModel would still invoke the notification itself but the changes should be reflected on the Model so that the Business logic can handle the requests.
So I want the Model to hold the state for the api client and the ViewModel for interaction with the component. I updated my code example a little so maybe it gets clearer. In the end I think I can do with what I have shown in the example if there is not a build in way to deal with it.
Would it still be possible to add
[CallerMemberName]
to theOnPropertyChanged()
Method?