Class TwoWayBindingHelper<TViewModel>
- Assembly
- Blazing.Mvvm.dll
Provides automatic two-way binding between View component parameters and ViewModel properties that are marked with the ViewParameterAttribute.
public sealed class TwoWayBindingHelper<TViewModel> : IDisposable where TViewModel : IViewModelBaseType Parameters
TViewModel-
The type of the ViewModel. Must implement IViewModelBase.
Inheritance
Implements
Remarks
This helper automatically detects EventCallback<T> parameters that follow the Blazor naming convention (e.g., {PropertyName}Changed) and wires them up to the corresponding ViewModel property changes. It handles proper subscription and disposal to prevent memory leaks.
Constructors
TwoWayBindingHelper(ComponentBase, TViewModel)
Initializes a new instance of the TwoWayBindingHelper<TViewModel> class.
public TwoWayBindingHelper(ComponentBase component, TViewModel viewModel)Parameters
componentComponentBase-
The component that owns this helper.
viewModelTViewModel-
The ViewModel to bind to.
Exceptions
- ArgumentNullException
-
Thrown when
componentorviewModelis null.
Methods
Dispose()
Releases all resources used by the TwoWayBindingHelper<TViewModel>.
public void Dispose()Remarks
This method unsubscribes from all ViewModel property change events to prevent memory leaks. It should be called during the component's Dispose method.
Initialize()
Initializes the two-way binding by scanning for EventCallback parameters and subscribing to ViewModel property changes.
public void Initialize()Remarks
This method should be called during the component's OnInitialized lifecycle method. It scans the component for EventCallback<T> properties that match the {PropertyName}Changed pattern and sets up automatic invocation when the corresponding ViewModel property changes.