Inherit RadzenSpreadsheetToolBase in merge/borders/conditional/validation tools

Replace the duplicated selection-binding boilerplate (cascading parameters,
IsDisabled, EventBinding<Selection>, OnParametersSet/OnSelectionChanged/Dispose)
with @inherits RadzenSpreadsheetToolBase, overriding only Feature - matching the
Insert* tools.
This commit is contained in:
Atanas Korchev
2026-06-17 18:26:52 +03:00
parent 8530e5f060
commit 9853c4aa2e
4 changed files with 8 additions and 144 deletions

View File

@@ -2,7 +2,7 @@
@using Radzen.Blazor
@using Radzen.Blazor.Spreadsheet
@using Radzen.Documents.Spreadsheet
@implements IDisposable
@inherits RadzenSpreadsheetToolBase
<RadzenSplitButton Click=@OnClick Icon="border_all" Disabled=@IsDisabled Variant="Variant.Outlined" ButtonStyle="ButtonStyle.Base" Size="ButtonSize.Small">
<ChildContent>
@@ -17,41 +17,7 @@
</RadzenSplitButton>
@code {
#nullable enable
[CascadingParameter]
public Worksheet? Worksheet { get; set; }
[CascadingParameter]
public ISpreadsheet? Spreadsheet { get; set; }
private bool IsDisabled
=> Worksheet?.Selection.Cell == CellRef.Invalid
|| Spreadsheet?.IsFeatureAllowed(SpreadsheetFeature.CellFormatting) == false;
private readonly EventBinding<Selection> selectionBinding;
public RadzenSpreadsheetCellBorders()
{
selectionBinding = new EventBinding<Selection>(
s => s.Changed += OnSelectionChanged,
s => s.Changed -= OnSelectionChanged);
}
protected override void OnParametersSet()
{
selectionBinding.Bind(Worksheet?.Selection);
}
private void OnSelectionChanged()
{
StateHasChanged();
}
public void Dispose()
{
selectionBinding.Dispose();
}
protected override SpreadsheetFeature? Feature => SpreadsheetFeature.CellFormatting;
private async Task OnClick(RadzenSplitButtonItem? item)
{

View File

@@ -4,7 +4,7 @@
@using Radzen.Blazor.Spreadsheet.Tools
@using Radzen.Documents.Spreadsheet
@inject DialogService DialogService
@implements IDisposable
@inherits RadzenSpreadsheetToolBase
<RadzenSplitButton Click=@OnClickAsync Icon="format_color_fill" Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_Conditional)) ?? "Conditional") Disabled=@IsDisabled Variant="Variant.Outlined" ButtonStyle="ButtonStyle.Base" Size="ButtonSize.Small">
<ChildContent>
@@ -17,41 +17,7 @@
</RadzenSplitButton>
@code {
#nullable enable
[CascadingParameter]
public Worksheet? Worksheet { get; set; }
[CascadingParameter]
public ISpreadsheet? Spreadsheet { get; set; }
private bool IsDisabled
=> Worksheet?.Selection.Cell == CellRef.Invalid
|| Spreadsheet?.IsFeatureAllowed(SpreadsheetFeature.ConditionalFormatting) == false;
private readonly EventBinding<Selection> selectionBinding;
public RadzenSpreadsheetConditionalFormat()
{
selectionBinding = new EventBinding<Selection>(
s => s.Changed += OnSelectionChanged,
s => s.Changed -= OnSelectionChanged);
}
protected override void OnParametersSet()
{
selectionBinding.Bind(Worksheet?.Selection);
}
private void OnSelectionChanged()
{
StateHasChanged();
}
public void Dispose()
{
selectionBinding.Dispose();
}
protected override SpreadsheetFeature? Feature => SpreadsheetFeature.ConditionalFormatting;
private async Task OnClickAsync(RadzenSplitButtonItem? item)
{

View File

@@ -4,7 +4,7 @@
@using Radzen.Blazor.Spreadsheet.Tools
@using Radzen.Documents.Spreadsheet
@inject DialogService DialogService
@implements IDisposable
@inherits RadzenSpreadsheetToolBase
<RadzenSplitButton Click=@OnClickAsync Icon="rule" Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_Validation)) ?? "Validation") Disabled=@IsDisabled Variant="Variant.Outlined" ButtonStyle="ButtonStyle.Base" Size="ButtonSize.Small">
<ChildContent>
@@ -14,41 +14,7 @@
</RadzenSplitButton>
@code {
#nullable enable
[CascadingParameter]
public Worksheet? Worksheet { get; set; }
[CascadingParameter]
public ISpreadsheet? Spreadsheet { get; set; }
private bool IsDisabled
=> Worksheet?.Selection.Cell == CellRef.Invalid
|| Spreadsheet?.IsFeatureAllowed(SpreadsheetFeature.DataValidation) == false;
private readonly EventBinding<Selection> selectionBinding;
public RadzenSpreadsheetDataValidation()
{
selectionBinding = new EventBinding<Selection>(
s => s.Changed += OnSelectionChanged,
s => s.Changed -= OnSelectionChanged);
}
protected override void OnParametersSet()
{
selectionBinding.Bind(Worksheet?.Selection);
}
private void OnSelectionChanged()
{
StateHasChanged();
}
public void Dispose()
{
selectionBinding.Dispose();
}
protected override SpreadsheetFeature? Feature => SpreadsheetFeature.DataValidation;
private async Task OnClickAsync(RadzenSplitButtonItem? item)
{

View File

@@ -2,7 +2,7 @@
@using Radzen.Blazor
@using Radzen.Blazor.Spreadsheet
@using Radzen.Documents.Spreadsheet
@implements IDisposable
@inherits RadzenSpreadsheetToolBase
<RadzenSplitButton Click=@OnClick Icon="merge_type" Disabled=@IsDisabled Variant="Variant.Outlined" ButtonStyle="ButtonStyle.Base" Size="ButtonSize.Small">
<ChildContent>
@@ -13,41 +13,7 @@
</RadzenSplitButton>
@code {
#nullable enable
[CascadingParameter]
public Worksheet? Worksheet { get; set; }
[CascadingParameter]
public ISpreadsheet? Spreadsheet { get; set; }
private bool IsDisabled
=> Worksheet?.Selection.Cell == CellRef.Invalid
|| Spreadsheet?.IsFeatureAllowed(SpreadsheetFeature.Merging) == false;
private readonly EventBinding<Selection> selectionBinding;
public RadzenSpreadsheetMergeCells()
{
selectionBinding = new EventBinding<Selection>(
s => s.Changed += OnSelectionChanged,
s => s.Changed -= OnSelectionChanged);
}
protected override void OnParametersSet()
{
selectionBinding.Bind(Worksheet?.Selection);
}
private void OnSelectionChanged()
{
StateHasChanged();
}
public void Dispose()
{
selectionBinding.Dispose();
}
protected override SpreadsheetFeature? Feature => SpreadsheetFeature.Merging;
private async Task OnClick(RadzenSplitButtonItem? item)
{