question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guidance on Two-Way Binding on a Model property

See original GitHub issue

Question

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:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
SSchulze1989commented, May 5, 2022

Thank you very much for the quick response and the change. Exactly what i needed and working like a charm!

0reactions
SSchulze1989commented, Apr 27, 2022

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 the OnPropertyChanged() Method?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found