Expose ParametersSet API

This commit is contained in:
2025-08-05 12:07:38 +02:00
parent 72b203fcda
commit 9e3f943628
3 changed files with 21 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.2.7</Version>
<Version>0.2.8</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
+8 -1
View File
@@ -15,7 +15,7 @@ public abstract class ViewModelBase<TViewModel, TView> : INotifyPropertyChanged
private set
{
field = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.View)));
this.NotifyPropertyChanged(nameof(this.View));
}
}
@@ -29,5 +29,12 @@ public abstract class ViewModelBase<TViewModel, TView> : INotifyPropertyChanged
this.View?.RefreshView();
}
public void NotifyPropertyChanged(string propertyName)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public virtual ValueTask Initialize(CancellationToken cancellationToken) => ValueTask.CompletedTask;
public virtual ValueTask ParametersSet(TView view, CancellationToken cancellationToken) => ValueTask.CompletedTask;
}
+12
View File
@@ -40,6 +40,18 @@ public abstract class ViewBase<TView, TViewModel> : ComponentBase
}
}
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
if (this is not TView view)
{
throw new InvalidOperationException($"View is not of type {typeof(TView).Name}. Actual type: {this.GetType().Name}");
}
using var initializationCts = new CancellationTokenSource(InitializationTimeout);
await this.ViewModel.ParametersSet(view, initializationCts.Token);
}
internal void RefreshView()
{
this.StateHasChanged();