- ChangeRGB(args.Value)) aria-label=@HexText />
+ ChangeRGB(args.Value!)) aria-label=@HexText />
@HexText
ChangeColor(args.Value, (color, value) => color.Red = value))
+ @oninput=@(args => ChangeColor(args.Value!, (color, value) => color.Red = value))
Change=@(red => ChangeColor(red, (color, value) => color.Red = value))
/>
@RedText
ChangeColor(args.Value, (color, value) => color.Green = value))
+ @oninput=@(args => ChangeColor(args.Value!, (color, value) => color.Green = value))
Change=@(green => ChangeColor(green, (color, value) => color.Green = value))
/>
@GreenText
ChangeColor(args.Value, (color, value) => color.Blue = value))
+ @oninput=@(args => ChangeColor(args.Value!, (color, value) => color.Blue = value))
Change=@(blue => ChangeColor(blue, (color, value) => color.Blue = value))
/>
@BlueText
ChangeAlpha(args.Value))
+ @oninput=@(args => ChangeAlpha(args.Value!))
Change=@(alpha => ChangeAlpha(alpha))
/>
@AlphaText
diff --git a/Radzen.Blazor/RadzenColorPicker.razor.cs b/Radzen.Blazor/RadzenColorPicker.razor.cs
index 6deeae19..098f7156 100644
--- a/Radzen.Blazor/RadzenColorPicker.razor.cs
+++ b/Radzen.Blazor/RadzenColorPicker.razor.cs
@@ -61,14 +61,14 @@ namespace Radzen.Blazor
///
/// The icon.
[Parameter]
- public string Icon { get; set; }
+ public string? Icon { get; set; }
///
/// Gets or sets the icon color.
///
/// The icon color.
[Parameter]
- public string IconColor { get; set; }
+ public string? IconColor { get; set; }
///
/// Gets or sets the hexadecimal color label text.
@@ -112,17 +112,17 @@ namespace Radzen.Blazor
[Parameter]
public string ButtonText { get; set; } = "OK";
- Popup Popup { get; set; }
+ Popup Popup { get; set; } = default!;
- internal event EventHandler SelectedColorChanged;
+ internal event EventHandler? SelectedColorChanged;
string AlphaGradientStart
{
get
{
var rgb = RGB.Parse(Color);
- rgb.Alpha = 0;
- return rgb.ToCSS();
+ rgb?.Alpha = 0;
+ return rgb?.ToCSS() ?? string.Empty;
}
}
@@ -131,8 +131,8 @@ namespace Radzen.Blazor
get
{
var rgb = RGB.Parse(Color);
- rgb.Alpha = 1;
- return rgb.ToCSS();
+ rgb?.Alpha = 1;
+ return rgb?.ToCSS() ?? string.Empty;
}
}
@@ -156,7 +156,7 @@ namespace Radzen.Blazor
get
{
var rgb = RGB.Parse(Color);
- return rgb.Red;
+ return rgb?.Red ?? default;
}
}
@@ -173,7 +173,7 @@ namespace Radzen.Blazor
get
{
var rgb = RGB.Parse(Color);
- return rgb.Green;
+ return rgb?.Green ?? default;
}
}
@@ -182,7 +182,7 @@ namespace Radzen.Blazor
get
{
var rgb = RGB.Parse(Color);
- return rgb.Blue;
+ return rgb?.Blue ?? default;
}
}
@@ -200,14 +200,17 @@ namespace Radzen.Blazor
await TriggerChange();
}
- Rect lastHslRect;
+ Rect? lastHslRect;
async Task OnSaturationMove(DraggableEventArgs args)
{
lastHslRect = args.Rect; ;
- SaturationHandleLeft = Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1);
- SaturationHandleTop = Math.Clamp((args.ClientY - args.Rect.Top) / args.Rect.Height, 0, 1);
+ if (args.Rect != null)
+ {
+ SaturationHandleLeft = Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1);
+ SaturationHandleTop = Math.Clamp((args.ClientY - args.Rect.Top) / args.Rect.Height, 0, 1);
+ }
await UpdateColorUsingHsvHandles();
}
@@ -241,17 +244,31 @@ namespace Radzen.Blazor
async Task ChangeRGB(object value)
{
- var rgb = RGB.Parse(value as string);
- if (rgb != null)
+ var colorString = value as string;
+ if (string.IsNullOrEmpty(colorString))
{
- rgb.Alpha = AlphaHandleLeft;
- await UpdateColor(rgb);
+ return;
}
+
+ var rgb = RGB.Parse(colorString);
+ if (rgb == null)
+ {
+ return;
+ }
+
+ rgb.Alpha = AlphaHandleLeft;
+ await UpdateColor(rgb);
}
internal async Task SelectColor(string value)
{
- await UpdateColor(RGB.Parse(value));
+ var rgb = RGB.Parse(value);
+ if (rgb == null)
+ {
+ return;
+ }
+
+ await UpdateColor(rgb);
if (!ShowButton)
{
@@ -259,8 +276,13 @@ namespace Radzen.Blazor
}
}
- async Task UpdateColor(RGB rgb)
+ async Task UpdateColor(RGB? rgb)
{
+ if (rgb == null)
+ {
+ return;
+ }
+
Color = rgb.ToCSS();
var hsv = rgb.ToHSV();
@@ -278,6 +300,10 @@ namespace Radzen.Blazor
if (value >= 0 && value <= 100)
{
var rgb = RGB.Parse(Color);
+ if (rgb == null)
+ {
+ return;
+ }
AlphaHandleLeft = rgb.Alpha = Math.Round(value / 100, 2);
Color = rgb.ToCSS();
@@ -288,7 +314,8 @@ namespace Radzen.Blazor
async Task ChangeAlpha(object alpha)
{
- if (Double.TryParse((string)alpha, out var value))
+ var alphaString = alpha as string;
+ if (alphaString != null && Double.TryParse(alphaString, out var value))
{
await ChangeAlpha(value);
}
@@ -299,6 +326,10 @@ namespace Radzen.Blazor
if (value >= 0 && value <= 255)
{
var rgb = RGB.Parse(Color);
+ if (rgb == null)
+ {
+ return;
+ }
update(rgb, value);
@@ -308,29 +339,36 @@ namespace Radzen.Blazor
async Task ChangeColor(object color, Action update)
{
- if (Double.TryParse((string)color, out var value))
+ var colorString = color as string;
+ if (colorString != null && Double.TryParse(colorString, out var value))
{
await ChangeColor(value, update);
}
}
- Rect lastAlphaRect;
+ Rect? lastAlphaRect;
async Task OnAlphaMove(DraggableEventArgs args)
{
lastAlphaRect = args.Rect;
- AlphaHandleLeft = Math.Round(Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1), 2);
+ if (args.Rect != null)
+ {
+ AlphaHandleLeft = Math.Round(Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1), 2);
+ }
await UpdateColorUsingHsvHandles();
}
- Rect lastHueRect;
+ Rect? lastHueRect;
async Task OnHueMove(DraggableEventArgs args)
{
lastHueRect = args.Rect;
- HueHandleLeft = Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1);
+ if (args.Rect != null)
+ {
+ HueHandleLeft = Math.Clamp((args.ClientX - args.Rect.Left) / args.Rect.Width, 0, 1);
+ }
await UpdateColorUsingHsvHandles();
}
@@ -384,7 +422,7 @@ namespace Radzen.Blazor
///
/// The child content.
[Parameter]
- public RenderFragment ChildContent { get; set; }
+ public RenderFragment? ChildContent { get; set; }
///
/// Gets or sets the render mode.
@@ -393,9 +431,9 @@ namespace Radzen.Blazor
[Parameter]
public PopupRenderMode PopupRenderMode { get; set; } = PopupRenderMode.Initial;
- double SaturationHandleLeft { get; set; } = 0;
- double SaturationHandleTop { get; set; } = 0;
- double HueHandleLeft { get; set; } = 0;
+ double SaturationHandleLeft { get; set; }
+ double SaturationHandleTop { get; set; }
+ double HueHandleLeft { get; set; }
double AlphaHandleLeft { get; set; } = 1;
string Color { get; set; } = "rgb(255, 255, 255)";
@@ -431,14 +469,18 @@ namespace Radzen.Blazor
if (value != Color)
{
- Color = value;
+ Color = value ?? string.Empty;
SelectedColorChanged?.Invoke(this, Color);
- var hsv = RGB.Parse(Color).ToHSV();
- SaturationHandleLeft = hsv.Saturation;
- SaturationHandleTop = 1 - hsv.Value;
- HueHandleLeft = hsv.Hue;
- AlphaHandleLeft = hsv.Alpha;
+ var hsvSource = RGB.Parse(Color);
+ if (hsvSource != null)
+ {
+ var hsv = hsvSource.ToHSV();
+ SaturationHandleLeft = hsv.Saturation;
+ SaturationHandleTop = 1 - hsv.Value;
+ HueHandleLeft = hsv.Hue;
+ AlphaHandleLeft = hsv.Alpha;
+ }
}
}
@@ -463,12 +505,15 @@ namespace Radzen.Blazor
{
preventKeyPress = true;
- if (lastHueRect == null)
+ if (lastHueRect == null && JSRuntime != null)
{
lastHueRect = await JSRuntime.InvokeAsync("Radzen.clientRect", (GetId() + "hue"));
}
- await OnHueMove(new DraggableEventArgs() { Rect = lastHueRect, ClientX = lastHueRect.Left + lastHueRect.Width * HueHandleLeft + (key == "ArrowLeft" ? -1 : 1) });
+ if (lastHueRect != null)
+ {
+ await OnHueMove(new DraggableEventArgs() { Rect = lastHueRect, ClientX = lastHueRect.Left + lastHueRect.Width * HueHandleLeft + (key == "ArrowLeft" ? -1 : 1) });
+ }
}
else if (key == "Escape")
{
@@ -488,12 +533,15 @@ namespace Radzen.Blazor
{
preventKeyPress = true;
- if (lastAlphaRect == null)
+ if (lastAlphaRect == null && JSRuntime != null)
{
lastAlphaRect = await JSRuntime.InvokeAsync("Radzen.clientRect", (GetId() + "alpha"));
}
- await OnAlphaMove(new DraggableEventArgs() { Rect = lastAlphaRect, ClientX = lastAlphaRect.Left + lastAlphaRect.Width * AlphaHandleLeft + (key == "ArrowLeft" ? -3 : 3) });
+ if (lastAlphaRect != null)
+ {
+ await OnAlphaMove(new DraggableEventArgs() { Rect = lastAlphaRect, ClientX = lastAlphaRect.Left + lastAlphaRect.Width * AlphaHandleLeft + (key == "ArrowLeft" ? -3 : 3) });
+ }
}
else if (key == "Escape")
{
@@ -509,7 +557,7 @@ namespace Radzen.Blazor
{
var key = args.Code != null ? args.Code : args.Key;
- if (lastHslRect == null)
+ if (lastHslRect == null && JSRuntime != null)
{
lastHslRect = await JSRuntime.InvokeAsync("Radzen.clientRect", (GetId() + "hsl"));
}
@@ -518,12 +566,15 @@ namespace Radzen.Blazor
{
preventKeyPress = true;
- await OnSaturationMove(new DraggableEventArgs()
+ if (lastHslRect != null)
{
- Rect = lastHslRect,
- ClientX = lastHslRect.Left + lastHslRect.Width * SaturationHandleLeft + (key == "ArrowLeft" ? -1 : key == "ArrowRight" ? 1 : 0),
- ClientY = lastHslRect.Top + lastHslRect.Height * SaturationHandleTop + (key == "ArrowUp" ? -1 : key == "ArrowDown" ? 1 : 0)
- });
+ await OnSaturationMove(new DraggableEventArgs()
+ {
+ Rect = lastHslRect,
+ ClientX = lastHslRect.Left + lastHslRect.Width * SaturationHandleLeft + (key == "ArrowLeft" ? -1 : key == "ArrowRight" ? 1 : 0),
+ ClientY = lastHslRect.Top + lastHslRect.Height * SaturationHandleTop + (key == "ArrowUp" ? -1 : key == "ArrowDown" ? 1 : 0)
+ });
+ }
}
else if (key == "Escape")
{
@@ -535,7 +586,7 @@ namespace Radzen.Blazor
}
}
- bool preventKeyPress = false;
+ bool preventKeyPress;
async Task OnKeyPress(KeyboardEventArgs args, Task task)
{
var key = args.Code != null ? args.Code : args.Key;
@@ -559,7 +610,10 @@ namespace Radzen.Blazor
internal async Task ClosePopup()
{
await Popup.CloseAsync();
- await JSRuntime.InvokeVoidAsync("Radzen.focusElement", GetId());
+ if (JSRuntime != null)
+ {
+ await JSRuntime.InvokeVoidAsync("Radzen.focusElement", GetId());
+ }
}
}
}
diff --git a/Radzen.Blazor/RadzenColorPickerItem.razor b/Radzen.Blazor/RadzenColorPickerItem.razor
index f96dc536..8e63b6a4 100644
--- a/Radzen.Blazor/RadzenColorPickerItem.razor
+++ b/Radzen.Blazor/RadzenColorPickerItem.razor
@@ -1,4 +1,4 @@
@using Radzen.Blazor.Rendering
OnKeyPress(args, OnClick()))" @onkeypress:preventDefault=preventKeyPress @onkeypress:stopPropagation>
+ tabindex="@(ColorPicker?.Disabled == true ? -1 : 0)" @onkeypress="@(args => OnKeyPress(args, OnClick()))" @onkeypress:preventDefault=preventKeyPress @onkeypress:stopPropagation>
diff --git a/Radzen.Blazor/RadzenColorPickerItem.razor.cs b/Radzen.Blazor/RadzenColorPickerItem.razor.cs
index 3624c159..e34d3e4f 100644
--- a/Radzen.Blazor/RadzenColorPickerItem.razor.cs
+++ b/Radzen.Blazor/RadzenColorPickerItem.razor.cs
@@ -16,13 +16,13 @@ namespace Radzen.Blazor
///
///
The value.
[Parameter]
- public string Value { get; set; }
+ public string Value { get; set; } = string.Empty;
- string Background
+ string? Background
{
get
{
- RGB rgb = RGB.Parse(Value);
+ RGB? rgb = RGB.Parse(Value);
return rgb?.ToCSS();
}
@@ -33,15 +33,18 @@ namespace Radzen.Blazor
///
///
The color picker.
[CascadingParameter]
- public RadzenColorPicker ColorPicker { get; set; }
+ public RadzenColorPicker? ColorPicker { get; set; }
private bool isSelected;
///
protected override Task OnInitializedAsync()
{
- ColorPicker.SelectedColorChanged += ColorPickerColorChanged;
- isSelected = ColorPicker.Value == Background;
+ if (ColorPicker != null)
+ {
+ ColorPicker.SelectedColorChanged += ColorPickerColorChanged;
+ isSelected = ColorPicker.Value == Background;
+ }
return base.OnInitializedAsync();
}
@@ -56,7 +59,7 @@ namespace Radzen.Blazor
}
}
- private void ColorPickerColorChanged(object colorPicker, string newValue)
+ private void ColorPickerColorChanged(object? colorPicker, string newValue)
{
var shouldBeSelected = newValue == Background;
if (isSelected != shouldBeSelected)
@@ -68,10 +71,13 @@ namespace Radzen.Blazor
async Task OnClick()
{
- await ColorPicker.SelectColor(Value);
+ if (ColorPicker != null)
+ {
+ await ColorPicker.SelectColor(Value);
+ }
}
- bool preventKeyPress = false;
+ bool preventKeyPress;
async Task OnKeyPress(KeyboardEventArgs args, Task task)
{
var key = args.Code != null ? args.Code : args.Key;
@@ -84,7 +90,10 @@ namespace Radzen.Blazor
}
else if (key == "Escape")
{
- await ColorPicker.ClosePopup();
+ if (ColorPicker != null)
+ {
+ await ColorPicker.ClosePopup();
+ }
}
else
{
diff --git a/Radzen.Blazor/RadzenColumn.razor.cs b/Radzen.Blazor/RadzenColumn.razor.cs
index eee172eb..e9ad2d5b 100644
--- a/Radzen.Blazor/RadzenColumn.razor.cs
+++ b/Radzen.Blazor/RadzenColumn.razor.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Components;
using Radzen.Blazor.Rendering;
using System;
+using System.Globalization;
namespace Radzen.Blazor
{
@@ -222,56 +223,56 @@ namespace Radzen.Blazor
///
///
The column order (0-12, "first", or "last"). Default is null (document order).
[Parameter]
- public string Order { get; set; }
+ public string? Order { get; set; }
///
/// Gets or sets the column order for extra small screens (breakpoint < 576px).
///
///
The column order (0-12, "first", or "last") on XS screens.
[Parameter]
- public string OrderXS { get; set; }
+ public string? OrderXS { get; set; }
///
/// Gets or sets the column order for small screens (breakpoint ≥ 576px).
///
///
The column order (0-12, "first", or "last") on SM screens.
[Parameter]
- public string OrderSM { get; set; }
+ public string? OrderSM { get; set; }
///
/// Gets or sets the column order for medium screens (breakpoint ≥ 768px).
///
///
The column order (0-12, "first", or "last") on MD screens.
[Parameter]
- public string OrderMD { get; set; }
+ public string? OrderMD { get; set; }
///
/// Gets or sets the column order for large screens (breakpoint ≥ 1024px).
///
///
The column order (0-12, "first", or "last") on LG screens.
[Parameter]
- public string OrderLG { get; set; }
+ public string? OrderLG { get; set; }
///
/// Gets or sets the column order for extra large screens (breakpoint ≥ 1280px).
///
///
The column order (0-12, "first", or "last") on XL screens.
[Parameter]
- public string OrderXL { get; set; }
+ public string? OrderXL { get; set; }
///
/// Gets or sets the column order for extra extra large screens (breakpoint ≥ 1536px).
///
///
The column order (0-12, "first", or "last") on XX screens.
[Parameter]
- public string OrderXX { get; set; }
+ public string? OrderXX { get; set; }
///
/// Gets the final CSS style rendered by the component. Combines it with a style custom attribute.
///
protected string GetStyle()
{
- if (Attributes != null && Attributes.TryGetValue("style", out var style) && !string.IsNullOrEmpty(Convert.ToString(@style)))
+ if (Attributes != null && Attributes.TryGetValue("style", out var style) && !string.IsNullOrEmpty(Convert.ToString(@style, CultureInfo.InvariantCulture)))
{
return $"{GetComponentStyle()} {@style}";
}
@@ -284,7 +285,7 @@ namespace Radzen.Blazor
///
protected string GetComponentStyle()
{
- return $"{Style}{(!string.IsNullOrEmpty(Style) && !Style.EndsWith(";") ? ";" : "")}";
+ return $"{Style}{(!string.IsNullOrEmpty(Style) && !Style.EndsWith(';') ? ";" : "")}";
}
///
@@ -304,13 +305,13 @@ namespace Radzen.Blazor
.AddSize("offset", nameof(OffsetLG), "lg", OffsetLG)
.AddSize("offset", nameof(OffsetXL), "xl", OffsetXL)
.AddSize("offset", nameof(OffsetXX), "xx", OffsetXX)
- .AddOrder("order", nameof(Order), Order)
- .AddOrder("order", nameof(OrderXS), "xs", OrderXS)
- .AddOrder("order", nameof(OrderSM), "sm", OrderSM)
- .AddOrder("order", nameof(OrderMD), "md", OrderMD)
- .AddOrder("order", nameof(OrderLG), "lg", OrderLG)
- .AddOrder("order", nameof(OrderXL), "xl", OrderXL)
- .AddOrder("order", nameof(OrderXX), "xx", OrderXX)
+ .AddOrder("order", nameof(Order), Order ?? string.Empty)
+ .AddOrder("order", nameof(OrderXS), "xs", OrderXS ?? string.Empty)
+ .AddOrder("order", nameof(OrderSM), "sm", OrderSM ?? string.Empty)
+ .AddOrder("order", nameof(OrderMD), "md", OrderMD ?? string.Empty)
+ .AddOrder("order", nameof(OrderLG), "lg", OrderLG ?? string.Empty)
+ .AddOrder("order", nameof(OrderXL), "xl", OrderXL ?? string.Empty)
+ .AddOrder("order", nameof(OrderXX), "xx", OrderXX ?? string.Empty)
.ToString();
}
}
\ No newline at end of file
diff --git a/Radzen.Blazor/RadzenColumnOptions.cs b/Radzen.Blazor/RadzenColumnOptions.cs
index 9e4a2fd6..aa36fb85 100644
--- a/Radzen.Blazor/RadzenColumnOptions.cs
+++ b/Radzen.Blazor/RadzenColumnOptions.cs
@@ -31,7 +31,10 @@ namespace Radzen.Blazor
///
protected override void Initialize()
{
- Chart.ColumnOptions = this;
+ if (Chart != null)
+ {
+ Chart.ColumnOptions = this;
+ }
}
///
diff --git a/Radzen.Blazor/RadzenColumnSeries.razor b/Radzen.Blazor/RadzenColumnSeries.razor
index 62f3f562..f597fc0d 100644
--- a/Radzen.Blazor/RadzenColumnSeries.razor
+++ b/Radzen.Blazor/RadzenColumnSeries.razor
@@ -10,19 +10,20 @@
@code {
public override RenderFragment Render(ScaleBase categoryScale, ScaleBase valueScale)
{
+ var chart = RequireChart();
var category = ComposeCategory(categoryScale);
var value = ComposeValue(valueScale);
- var ticks = Chart.ValueScale.Ticks(Chart.ValueAxis.TickDistance);
- var y0 = Chart.ValueScale.Scale(Math.Max(0, ticks.Start));
- var style = $"clip-path: url(#{Chart.ClipPath}); -webkit-clip-path: url(#{Chart.ClipPath});";
+ var ticks = chart.ValueScale.Ticks(chart.ValueAxis.TickDistance);
+ var y0 = chart.ValueScale.Scale(Math.Max(0, ticks.Start));
+ var style = $"clip-path: url(#{chart.ClipPath}); -webkit-clip-path: url(#{chart.ClipPath});";
var columnSeries = VisibleColumnSeries;
var index = columnSeries.IndexOf(this);
- var padding = Chart.ColumnOptions.Margin;
+ var padding = chart.ColumnOptions.Margin;
var bandWidth = BandWidth;
var width = bandWidth / columnSeries.Count() - padding + padding / columnSeries.Count();;
- var className = $"rz-column-series rz-series-{Chart.Series.IndexOf(this)}";
+ var className = $"rz-column-series rz-series-{chart.Series.IndexOf(this)}";
return
@
@@ -31,7 +32,7 @@
var x = category(data) - bandWidth / 2 + index * width + index * padding;
var y = value(data);
var itemValue = Value(data);
- var radius = Chart.ColumnOptions.Radius;
+ var radius = chart.ColumnOptions.Radius;
var height = Math.Abs(y0 - y);
if (radius > width / 2 || radius > height)
diff --git a/Radzen.Blazor/RadzenColumnSeries.razor.cs b/Radzen.Blazor/RadzenColumnSeries.razor.cs
index 9e07c9d0..d7cc979b 100644
--- a/Radzen.Blazor/RadzenColumnSeries.razor.cs
+++ b/Radzen.Blazor/RadzenColumnSeries.razor.cs
@@ -38,7 +38,7 @@ namespace Radzen.Blazor
///
/// The fill color as a CSS color value.
[Parameter]
- public string Fill { get; set; }
+ public string? Fill { get; set; }
///
/// Gets or sets a collection of fill colors to apply to individual columns in sequence.
@@ -47,7 +47,7 @@ namespace Radzen.Blazor
///
/// An enumerable collection of CSS color values.
[Parameter]
- public IEnumerable Fills { get; set; }
+ public IEnumerable? Fills { get; set; }
///
/// Gets or sets the stroke (border) color applied to all columns in the series.
@@ -55,7 +55,7 @@ namespace Radzen.Blazor
///
/// The stroke color as a CSS color value.
[Parameter]
- public string Stroke { get; set; }
+ public string? Stroke { get; set; }
///
/// Gets or sets a collection of stroke colors to apply to individual column borders in sequence.
@@ -64,7 +64,7 @@ namespace Radzen.Blazor
///
/// An enumerable collection of CSS color values for borders.
[Parameter]
- public IEnumerable Strokes { get; set; }
+ public IEnumerable? Strokes { get; set; }
///
/// Gets or sets the width of the column border in pixels.
@@ -89,7 +89,7 @@ namespace Radzen.Blazor
///
/// A collection of value ranges and their associated fill colors.
[Parameter]
- public IList FillRange { get; set; }
+ public IList? FillRange { get; set; }
///
/// Gets or sets value-based color ranges that dynamically color column borders based on their values.
@@ -97,14 +97,14 @@ namespace Radzen.Blazor
///
/// A collection of value ranges and their associated stroke colors.
[Parameter]
- public IList StrokeRange { get; set; }
+ public IList? StrokeRange { get; set; }
///
public override string Color
{
get
{
- return Fill;
+ return Fill ?? string.Empty;
}
}
@@ -117,7 +117,7 @@ namespace Radzen.Blazor
return 0;
}
- return Items.Count();
+ return Items.Count;
}
}
@@ -125,7 +125,8 @@ namespace Radzen.Blazor
{
get
{
- return Chart.Series.Where(series => series is IChartColumnSeries).Cast().ToList();
+ var chart = RequireChart();
+ return chart.Series.Where(series => series is IChartColumnSeries).Cast().ToList();
}
}
@@ -163,13 +164,14 @@ namespace Radzen.Blazor
{
var columnSeries = VisibleColumnSeries;
- if (Chart.ColumnOptions.Width.HasValue)
+ var chart = RequireChart();
+ if (chart.ColumnOptions.Width.HasValue)
{
- return Chart.ColumnOptions.Width.Value * columnSeries.Count + Chart.ColumnOptions.Margin * (columnSeries.Count - 1);
+ return chart.ColumnOptions.Width.Value * columnSeries.Count + chart.ColumnOptions.Margin * (columnSeries.Count - 1);
}
else
{
- var availableWidth = Chart.CategoryScale.OutputSize - (Chart.CategoryAxis.Padding * 2);
+ var availableWidth = chart.CategoryScale.OutputSize - (chart.CategoryAxis.Padding * 2);
var bands = columnSeries.Cast().Max(series => series.Count) + 2;
return availableWidth / bands;
}
@@ -185,12 +187,13 @@ namespace Radzen.Blazor
///
internal override double TooltipX(TItem item)
{
+ var chart = RequireChart();
var columnSeries = VisibleColumnSeries;
var index = columnSeries.IndexOf(this);
- var padding = Chart.ColumnOptions.Margin;
+ var padding = chart.ColumnOptions.Margin;
var bandWidth = BandWidth;
- var width = bandWidth / columnSeries.Count() - padding + padding / columnSeries.Count();
- var category = ComposeCategory(Chart.CategoryScale);
+ var width = bandWidth / columnSeries.Count - padding + padding / columnSeries.Count;
+ var category = ComposeCategory(chart.CategoryScale);
var x = category(item) - bandWidth / 2 + index * width + index * padding;
return x + width / 2;
@@ -205,16 +208,17 @@ namespace Radzen.Blazor
///
public override (object, Point) DataAt(double x, double y)
{
- var category = ComposeCategory(Chart.CategoryScale);
- var value = ComposeValue(Chart.ValueScale);
- var ticks = Chart.ValueScale.Ticks(Chart.ValueAxis.TickDistance);
- var y0 = Chart.ValueScale.Scale(Math.Max(0, ticks.Start));
+ var chart = RequireChart();
+ var category = ComposeCategory(chart.CategoryScale);
+ var value = ComposeValue(chart.ValueScale);
+ var ticks = chart.ValueScale.Ticks(chart.ValueAxis.TickDistance);
+ var y0 = chart.ValueScale.Scale(Math.Max(0, ticks.Start));
var columnSeries = VisibleColumnSeries;
var index = columnSeries.IndexOf(this);
- var padding = Chart.ColumnOptions.Margin;
+ var padding = chart.ColumnOptions.Margin;
var bandWidth = BandWidth;
- var width = Chart.ColumnOptions.Width ?? bandWidth / columnSeries.Count() - padding + padding / columnSeries.Count();
+ var width = chart.ColumnOptions.Width ?? bandWidth / columnSeries.Count - padding + padding / columnSeries.Count;
foreach (var data in Items)
{
@@ -226,11 +230,11 @@ namespace Radzen.Blazor
if (startX <= x && x <= endX && startY <= y && y <= endY)
{
- return (data, new Point() { X = x, Y = y });
+ return (data!, new Point() { X = x, Y = y });
}
}
- return (null, null);
+ return (default!, new Point());
}
///
@@ -240,16 +244,20 @@ namespace Radzen.Blazor
int sign;
- foreach (var d in Data)
+ var chart = RequireChart();
+ if (Data != null)
{
- sign = Value(d) < 0 ? -1 : Value(d) == 0 ? 0 : 1;
-
- list.Add(new ChartDataLabel
+ foreach (var d in Data)
{
- Position = new Point() { X = TooltipX(d) + offsetX, Y = TooltipY(d) - offsetY - (16 * sign) },
- TextAnchor = "middle",
- Text = Chart.ValueAxis.Format(Chart.ValueScale, Value(d))
- });
+ sign = Value(d) < 0 ? -1 : Value(d) == 0 ? 0 : 1;
+
+ list.Add(new ChartDataLabel
+ {
+ Position = new Point() { X = TooltipX(d) + offsetX, Y = TooltipY(d) - offsetY - (16 * sign) },
+ TextAnchor = "middle",
+ Text = chart.ValueAxis.Format(chart.ValueScale, Value(d))
+ });
+ }
}
return list;
diff --git a/Radzen.Blazor/RadzenCompareValidator.cs b/Radzen.Blazor/RadzenCompareValidator.cs
index 5899c5fb..6219522a 100644
--- a/Radzen.Blazor/RadzenCompareValidator.cs
+++ b/Radzen.Blazor/RadzenCompareValidator.cs
@@ -75,7 +75,7 @@ namespace Radzen.Blazor
/// Specifies the value to compare with.
///
[Parameter]
- public object Value { get; set; }
+ public object? Value { get; set; }
///
/// Specifies the comparison operator. Set to CompareOperator.Equal by default.
@@ -90,9 +90,9 @@ namespace Radzen.Blazor
[Parameter]
public virtual bool ValidateOnComponentValueChange { get; set; } = true;
- private int Compare(object componentValue) => componentValue switch
+ private int Compare(object? componentValue) => componentValue switch
{
- string stringValue => string.Compare(stringValue, (string)Value, false, Culture),
+ string stringValue => string.Compare(stringValue, Value as string, StringComparison.Ordinal),
IComparable comparable => comparable.CompareTo(Value),
_ => 0,
};
@@ -107,7 +107,7 @@ namespace Radzen.Blazor
if (ValidateOnComponentValueChange && (valueChanged || visibleChanged) && !firstRender && Visible)
{
- var component = Form.FindComponent(Component);
+ var component = Form?.FindComponent(Component);
if (component != null && component.FieldIdentifier.FieldName != null)
{
IsValid = Validate(component);
@@ -135,7 +135,9 @@ namespace Radzen.Blazor
///
protected override bool Validate(IRadzenFormComponent component)
{
- var compareResult = Compare(component.GetValue());
+ ArgumentNullException.ThrowIfNull(component);
+ var componentValue = component.GetValue();
+ var compareResult = Compare(componentValue);
return Operator switch
{
diff --git a/Radzen.Blazor/RadzenComponent.cs b/Radzen.Blazor/RadzenComponent.cs
index 754a9a7b..4fc769d4 100644
--- a/Radzen.Blazor/RadzenComponent.cs
+++ b/Radzen.Blazor/RadzenComponent.cs
@@ -24,7 +24,7 @@ namespace Radzen
///
/// The unmatched attributes dictionary.
[Parameter(CaptureUnmatchedValues = true)]
- public IReadOnlyDictionary Attributes { get; set; }
+ public IReadOnlyDictionary? Attributes { get; set; }
///
/// Gets a reference to the HTML element rendered by this component.
@@ -80,9 +80,9 @@ namespace Radzen
///
/// The cascaded default culture.
[CascadingParameter(Name = nameof(DefaultCulture))]
- public CultureInfo DefaultCulture { get; set; }
+ public CultureInfo? DefaultCulture { get; set; }
- private CultureInfo culture;
+ private CultureInfo? culture;
///
/// Raises .
@@ -114,7 +114,7 @@ namespace Radzen
///
/// The style.
[Parameter]
- public virtual string Style { get; set; }
+ public virtual string? Style { get; set; }
///
/// Gets or sets a value indicating whether this is visible. Invisible components are not rendered.
@@ -128,7 +128,7 @@ namespace Radzen
///
protected string GetCssClass()
{
- if (Attributes != null && Attributes.TryGetValue("class", out var @class) && !string.IsNullOrEmpty(Convert.ToString(@class)))
+ if (Attributes != null && Attributes.TryGetValue("class", out var @class) && !string.IsNullOrEmpty(Convert.ToString(@class, Culture)))
{
return $"{GetComponentCssClass()} {@class}";
}
@@ -140,9 +140,9 @@ namespace Radzen
/// Gets the unique identifier.
///
/// Returns the id attribute (if specified) or generates a random one.
- protected virtual string GetId()
+ protected virtual string? GetId()
{
- if (Attributes != null && Attributes.TryGetValue("id", out var id) && !string.IsNullOrEmpty(Convert.ToString(@id)))
+ if (Attributes != null && Attributes.TryGetValue("id", out var id) && !string.IsNullOrEmpty(Convert.ToString(@id, Culture)))
{
return $"{@id}";
}
@@ -158,7 +158,7 @@ namespace Radzen
return "";
}
- Debouncer debouncer = new Debouncer();
+ Debouncer? debouncer = new Debouncer();
///
/// Debounces the specified action.
@@ -167,21 +167,21 @@ namespace Radzen
/// The milliseconds.
protected void Debounce(Func action, int milliseconds = 500)
{
- debouncer.Debounce(milliseconds, action);
+ debouncer?.Debounce(milliseconds, action);
}
///
/// Gets or sets the unique identifier.
///
/// The unique identifier.
- public string UniqueID { get; set; }
+ public string? UniqueID { get; set; }
///
/// Gets or sets the js runtime.
///
/// The js runtime.
[Inject]
- protected IJSRuntime JSRuntime { get; set; }
+ protected IJSRuntime? JSRuntime { get; set; }
///
/// Gets or sets a value indicating whether is available.
@@ -193,10 +193,10 @@ namespace Radzen
///
protected override void OnInitialized()
{
- UniqueID = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace("/", "-").Replace("+", "-").Substring(0, 10);
+ UniqueID = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace("/", "-", StringComparison.Ordinal).Replace("+", "-", StringComparison.Ordinal).Substring(0, 10);
}
- private bool visibleChanged = false;
+ private bool visibleChanged;
private bool firstRender = true;
///
@@ -218,7 +218,7 @@ namespace Radzen
}
}
- private DotNetObjectReference reference;
+ private DotNetObjectReference? reference;
///
/// Gets the reference for the current component.
@@ -250,7 +250,7 @@ namespace Radzen
{
visibleChanged = false;
- if (Visible)
+ if (Visible && JSRuntime != null)
{
await AddContextMenu();
@@ -297,7 +297,7 @@ namespace Radzen
///
protected virtual async System.Threading.Tasks.Task AddContextMenu()
{
- if (ContextMenu.HasDelegate)
+ if (ContextMenu.HasDelegate && JSRuntime != null)
{
await JSRuntime.InvokeVoidAsync("Radzen.addContextMenu", GetId(), Reference);
}
@@ -315,7 +315,7 @@ namespace Radzen
}
}
- internal bool disposed = false;
+ internal bool disposed;
///
/// Detaches event handlers and disposes .
@@ -324,10 +324,12 @@ namespace Radzen
{
disposed = true;
+ debouncer?.Dispose();
+ debouncer = null;
reference?.Dispose();
reference = null;
- if (IsJSRuntimeAvailable)
+ if (IsJSRuntimeAvailable && JSRuntime != null && !string.IsNullOrEmpty(UniqueID))
{
if (ContextMenu.HasDelegate)
{
diff --git a/Radzen.Blazor/RadzenComponentActivator.cs b/Radzen.Blazor/RadzenComponentActivator.cs
index 4f440701..709c7c6a 100644
--- a/Radzen.Blazor/RadzenComponentActivator.cs
+++ b/Radzen.Blazor/RadzenComponentActivator.cs
@@ -51,26 +51,31 @@ namespace Radzen
///
public IComponent CreateInstance(Type componentType)
{
+ ArgumentNullException.ThrowIfNull(componentType);
+
if (!typeof(IComponent).IsAssignableFrom(componentType))
{
throw new ArgumentException($"The type {componentType.FullName} does not implement {nameof(IComponent)}.", nameof(componentType));
}
- if (replacedTypes.ContainsKey(componentType))
+ if (replacedTypes.TryGetValue(componentType, out var replacedType))
{
- componentType = replacedTypes[componentType];
+ componentType = replacedType;
}
else if (componentType.IsGenericType)
{
var genericTypeDefinition = componentType.GetGenericTypeDefinition();
- if (replacedTypes.ContainsKey(genericTypeDefinition))
+ if (replacedTypes.TryGetValue(genericTypeDefinition, out var replacedGenericType))
{
- componentType = replacedTypes[genericTypeDefinition].MakeGenericType(componentType.GetGenericArguments());
+ componentType = replacedGenericType.MakeGenericType(componentType.GetGenericArguments());
}
}
- return (IComponent)Activator.CreateInstance(componentType);
+ var instance = Activator.CreateInstance(componentType)
+ ?? throw new InvalidOperationException($"Unable to create an instance of '{componentType.FullName}'.");
+
+ return (IComponent)instance;
}
}
}
\ No newline at end of file
diff --git a/Radzen.Blazor/RadzenComponentWithChildren.cs b/Radzen.Blazor/RadzenComponentWithChildren.cs
index 2dcc30d4..938db5a0 100644
--- a/Radzen.Blazor/RadzenComponentWithChildren.cs
+++ b/Radzen.Blazor/RadzenComponentWithChildren.cs
@@ -13,6 +13,6 @@ public class RadzenComponentWithChildren : RadzenComponent
///
/// The content of the child.
[Parameter]
- public RenderFragment ChildContent { get; set; }
+ public RenderFragment? ChildContent { get; set; }
}
diff --git a/Radzen.Blazor/RadzenComponents.razor b/Radzen.Blazor/RadzenComponents.razor
index ecff8491..8171dd98 100644
--- a/Radzen.Blazor/RadzenComponents.razor
+++ b/Radzen.Blazor/RadzenComponents.razor
@@ -10,5 +10,5 @@
///
/// The attributes.
[Parameter(CaptureUnmatchedValues = true)]
- public IReadOnlyDictionary Attributes { get; set; }
+ public IReadOnlyDictionary? Attributes { get; set; }
}
\ No newline at end of file
diff --git a/Radzen.Blazor/RadzenContent.razor.cs b/Radzen.Blazor/RadzenContent.razor.cs
index 1cb5f298..da01b31d 100644
--- a/Radzen.Blazor/RadzenContent.razor.cs
+++ b/Radzen.Blazor/RadzenContent.razor.cs
@@ -12,7 +12,7 @@ namespace Radzen.Blazor
///
/// The container.
[Parameter]
- public string Container { get; set; }
+ public string? Container { get; set; }
///
protected override string GetComponentCssClass()
diff --git a/Radzen.Blazor/RadzenContentContainer.razor.cs b/Radzen.Blazor/RadzenContentContainer.razor.cs
index 802990f2..710e83fc 100644
--- a/Radzen.Blazor/RadzenContentContainer.razor.cs
+++ b/Radzen.Blazor/RadzenContentContainer.razor.cs
@@ -12,6 +12,6 @@ namespace Radzen.Blazor
///
/// The name.
[Parameter]
- public string Name { get; set; }
+ public string? Name { get; set; }
}
}
diff --git a/Radzen.Blazor/RadzenContextMenu.razor b/Radzen.Blazor/RadzenContextMenu.razor
index f7a26049..a544119b 100644
--- a/Radzen.Blazor/RadzenContextMenu.razor
+++ b/Radzen.Blazor/RadzenContextMenu.razor
@@ -5,16 +5,16 @@
@foreach (var menu in menus)
{
- @if (menu.Options.ChildContent != null)
+ @if (menu.Options?.ChildContent != null)
{
}
- else if (menu.Options.Items != null && menu.Options.Items.Any())
+ else if (menu?.Options?.Items != null && menu.Options.Items.Any())
{