fix nullable warnings in controls.
MODIFY
WalletWasabi.Fluent/Controls/AdornerCanvas.cs
WalletWasabi.Fluent/Controls/AdornerCanvas.cs
@@ -5,8 +5,6 @@ using Avalonia.Media;
using Avalonia.Rendering;
using Avalonia.VisualTree;
-#nullable enable
-
namespace WalletWasabi.Fluent.Controls;
/// <summary>
@@ -145,15 +143,18 @@ public class AdornerCanvas : Canvas, ICustomSimpleHitTest
clip.Rect = clipBounds;
}
- private void ChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+ private void ChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
+ if (e.NewItems is { })
+ {
foreach (Visual i in e.NewItems)
{
UpdateAdornedElement(i, i.GetValue(AdornedElementProperty));
}
+ }
break;
}

MODIFY
WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs
WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs
@@ -44,7 +44,7 @@ public class CurrencyEntryBox : TextBox
private readonly CultureInfo _customCultureInfo;
private readonly char _decimalSeparator = '.';
private readonly char _groupSeparator = ' ';
- private readonly Regex _regexBTCFormat;
+ private readonly Regex _regexBtcFormat;
private readonly Regex _regexDecimalCharsOnly;
private readonly Regex _regexConsecutiveSpaces;
private readonly Regex _regexGroupAndDecimal;
@@ -75,7 +75,7 @@ public class CurrencyEntryBox : TextBox
Watermark = "0 BTC";
Text = string.Empty;
- _regexBTCFormat =
+ _regexBtcFormat =
new Regex(
$"^(?<Whole>[0-9{_groupSeparator}]*)(\\{_decimalSeparator}?(?<Frac>[0-9{_groupSeparator}]*))$",
RegexOptions.Compiled);
@@ -195,7 +195,7 @@ public class CurrencyEntryBox : TextBox
{
// Check if it has a decimal separator.
var trailingDecimal = preComposedText.Length > 0 && preComposedText[^1] == _decimalSeparator;
- var match = _regexBTCFormat.Match(preComposedText);
+ var match = _regexBtcFormat.Match(preComposedText);
// Ignore group chars on count of the whole part of the decimal.
var wholeStr = match.Groups["Whole"].ToString();
@@ -255,16 +255,16 @@ public class CurrencyEntryBox : TextBox
protected override void OnKeyDown(KeyEventArgs e)
{
- DoPasteCheckAsync(e);
+ DoPasteCheck(e);
}
- private async void DoPasteCheckAsync(KeyEventArgs e)
+ private void DoPasteCheck(KeyEventArgs e)
{
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>();
- bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));
+ bool Match(IEnumerable<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));
- if (Match(keymap.Paste))
+ if (keymap is { } && Match(keymap.Paste))
{
ModifiedPasteAsync();
}
@@ -276,7 +276,9 @@ public class CurrencyEntryBox : TextBox
public async void ModifiedPasteAsync()
{
- var text = await AvaloniaLocator.Current.GetService<IClipboard>().GetTextAsync();
+ if (AvaloniaLocator.Current.GetService<IClipboard>() is { } clipboard)
+ {
+ var text = await clipboard.GetTextAsync();
if (string.IsNullOrEmpty(text))
{
@@ -300,12 +302,13 @@ public class CurrencyEntryBox : TextBox
OnTextInput(new TextInputEventArgs { Text = text });
}
}
+ }
// Pre-composes the TextInputEventArgs to see the potential Text that is to
// be committed to the TextPresenter in this control.
// An event in Avalonia's TextBox with this function should be implemented there for brevity.
- private string PreComposeText(string input)
+ private string PreComposeText(string? input)
{
input = RemoveInvalidCharacters(input);
var preComposedText = Text ?? "";

MODIFY
WalletWasabi.Fluent/Controls/PreviewItem.axaml.cs
WalletWasabi.Fluent/Controls/PreviewItem.axaml.cs
@@ -40,8 +40,12 @@ public class PreviewItem : ContentControl
if (obj.ToString() is { } text)
{
_copyButtonPressedStopwatch = Stopwatch.StartNew();
+
+ if (Application.Current is { Clipboard: { } })
+ {
await Application.Current.Clipboard.SetTextAsync(text);
}
+ }
});
this.WhenAnyValue(

MODIFY
WalletWasabi.Fluent/Controls/QrCode.cs
WalletWasabi.Fluent/Controls/QrCode.cs
@@ -16,7 +16,7 @@ namespace WalletWasabi.Fluent.Controls;
public class QrCode : Control
{
private const int MatrixPadding = 2;
- private const int MinimumBitmapSizePixelWH = 512;
+ private const int MinimumBitmapSizePixelWh = 512;
public static readonly DirectProperty<QrCode, ReactiveCommand<string, Unit>> SaveCommandProperty =
AvaloniaProperty.RegisterDirect<QrCode, ReactiveCommand<string, Unit>>(
@@ -48,7 +48,11 @@ public class QrCode : Control
}
});
- _saveCommand = ReactiveCommand.CreateFromTask<string, Unit>(SaveQrCodeAsync);
+ _saveCommand = ReactiveCommand.CreateFromTask<string, Unit>(async address =>
+ {
+ await SaveQrCodeAsync(address);
+ return Unit.Default;
+ });
SaveCommand.ThrownExceptions
.ObserveOn(RxApp.TaskpoolScheduler)
@@ -74,11 +78,11 @@ public class QrCode : Control
set => SetAndRaise(MatrixProperty, ref _matrix, value);
}
- public async Task<Unit> SaveQrCodeAsync(string address)
+ public async Task SaveQrCodeAsync(string address)
{
if (FinalMatrix is null)
{
- return Unit.Default;
+ return;
}
var sfd = new SaveFileDialog();
@@ -88,8 +92,9 @@ public class QrCode : Control
sfd.Filters.Add(new FileDialogFilter()
{ Name = "Portable Network Graphics (PNG) Image file", Extensions = { "png" } });
- var visualRoot = (ClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime;
- var path = await sfd.ShowAsync(visualRoot.MainWindow);
+ if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
+ {
+ var path = await sfd.ShowAsync(lifetime.MainWindow);
if (!string.IsNullOrWhiteSpace(path))
{
@@ -100,24 +105,23 @@ public class QrCode : Control
path = $"{path}.png";
}
- var qrCodeSize = GetQRCodeSize(FinalMatrix, Bounds.Size);
+ var qrCodeSize = GetQrCodeSize(FinalMatrix, Bounds.Size);
var pixSize = PixelSize.FromSize(qrCodeSize.coercedSize, 1);
- if (pixSize.Width < MinimumBitmapSizePixelWH || pixSize.Height < MinimumBitmapSizePixelWH)
+ if (pixSize.Width < MinimumBitmapSizePixelWh || pixSize.Height < MinimumBitmapSizePixelWh)
{
- pixSize = new PixelSize(MinimumBitmapSizePixelWH, MinimumBitmapSizePixelWH);
+ pixSize = new PixelSize(MinimumBitmapSizePixelWh, MinimumBitmapSizePixelWh);
}
using var rtb = new RenderTargetBitmap(pixSize);
using (var rtbCtx = rtb.CreateDrawingContext(null))
{
- DrawQRCodeImage(rtbCtx, FinalMatrix, pixSize.ToSize(1));
+ DrawQrCodeImage(rtbCtx, FinalMatrix, pixSize.ToSize(1));
}
rtb.Save(path);
}
-
- return Unit.Default;
+ }
}
private bool[,] AddPaddingToMatrix(bool[,] source)
@@ -139,12 +143,12 @@ public class QrCode : Control
return paddedMatrix;
}
- private (int indexW, int indexH) GetMatrixIndexSize(bool[,]? source) =>
+ private (int indexW, int indexH) GetMatrixIndexSize(bool[,] source) =>
(source.GetUpperBound(0) + 1, source.GetUpperBound(1) + 1);
- private void DrawQRCodeImage(IDrawingContextImpl ctx, bool[,]? source, Size size)
+ private void DrawQrCodeImage(IDrawingContextImpl ctx, bool[,] source, Size size)
{
- var qrCodeSize = GetQRCodeSize(source, size);
+ var qrCodeSize = GetQrCodeSize(source, size);
var (indexW, indexH) = GetMatrixIndexSize(source);
var gcf = qrCodeSize.gridCellFactor;
@@ -174,10 +178,10 @@ public class QrCode : Control
return;
}
- DrawQRCodeImage(context.PlatformImpl, source, Bounds.Size);
+ DrawQrCodeImage(context.PlatformImpl, source, Bounds.Size);
}
- private (Size coercedSize, double gridCellFactor) GetQRCodeSize(bool[,] source, Size size)
+ private (Size coercedSize, double gridCellFactor) GetQrCodeSize(bool[,] source, Size size)
{
var (indexW, indexH) = GetMatrixIndexSize(source);
@@ -202,6 +206,6 @@ public class QrCode : Control
return new Size();
}
- return GetQRCodeSize(source, availableSize).coercedSize;
+ return GetQrCodeSize(source, availableSize).coercedSize;
}
}

MODIFY
WalletWasabi.Fluent/Controls/ResponsivePanelState.cs
WalletWasabi.Fluent/Controls/ResponsivePanelState.cs
@@ -74,10 +74,15 @@ internal class ResponsivePanelState
public Size MeasureArrange(bool isMeasure)
{
+ if (ColumnHints is null)
+ {
+ return new Size();
+ }
+
var layoutIndex = 0;
var totalColumns = ColumnHints[layoutIndex];
- if (!double.IsInfinity(Width))
+ if (!double.IsInfinity(Width) && WidthTriggers is { })
{
for (var i = WidthTriggers.Count - 1; i >= 0; i--)
{

fix nullable warnings in controls.