New QR Code control for Avalonia
ADD
WalletWasabi.Gui/Controls/QrCode.cs
+using System;
+using System.Collections.Generic;
+using Avalonia;
+using Avalonia.Collections;
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using Avalonia.Data;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.Layout;
+using Avalonia.LogicalTree;
+using Avalonia.Media;
+using Avalonia.Metadata;
+using Avalonia.Rendering;
+using Avalonia.Styling;
+using Avalonia.VisualTree;
+
+namespace WalletWasabi.Gui.Controls
+{
+ public class QrCode : Control
+ {
+ public static readonly DirectProperty<QrCode, bool[,]> MatrixProperty =
+ AvaloniaProperty.RegisterDirect<QrCode, bool[,]>(
+ nameof(Matrix),
+ o => o.Matrix,
+ (o, v) => o.Matrix = v);
+
+
+ private bool[,] _matrix;
+
+ [Content]
+ public bool[,] Matrix
+ {
+ get { return _matrix; }
+ set { SetAndRaise(MatrixProperty, ref _matrix, value); }
+ }
+
+ public override void Render(DrawingContext context)
+ {
+ var source = Matrix;
+
+ if (source != null)
+ {
+ var h = source.GetUpperBound(0);
+ var w = source.GetUpperBound(1);
+
+ var minDimension = (float)Math.Min(w, h);
+ var minBound = Math.Min(Bounds.Width, Bounds.Height);
+ var factor = minBound / minDimension;
+
+ for(var i = 0; i <= h; i++)
+ {
+ for(var j = 0; j <= w; j++)
+ {
+ var cellValue = source[i, j];
+ var color = cellValue ? Brushes.Black : Brushes.White;
+ var rect = new Rect(i*factor, j*factor, factor, factor);
+ context.FillRectangle(color, rect);
+ }
+ }
+ }
+ }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ var source = Matrix;
+
+ if (source == null || source.Length == 0)
+ return new Size();
+
+ var max = Math.Min(availableSize.Width, availableSize.Height);
+
+ var size = new Size(max, max);
+
+ return size;
+ }
+
+ }
+}
\ No newline at end of file

MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
using System.Collections.Generic;
using System.Text;
using WalletWasabi.KeyManagement;
+using Gma.QrCodeNet.Encoding;
+using Gma.QrCodeNet.Encoding.Windows.Render;
+using Avalonia.Media.Imaging;
namespace WalletWasabi.Gui.ViewModels
{
@@ -17,5 +20,16 @@ namespace WalletWasabi.Gui.ViewModels
public string Label => Model.Label;
public string Address => Model.GetP2wpkhAddress(Global.Network).ToString();
+
+
+ public bool[,] QrCode
+ {
+ get
+ {
+ var encoder = new QrEncoder(ErrorCorrectionLevel.H);
+ encoder.TryEncode(Address, out var qrCode);
+ return qrCode.Matrix.InternalArray;
+ }
+ }
}
}

MODIFY
WalletWasabi.Gui/WalletWasabi.Gui.csproj
WalletWasabi.Gui/WalletWasabi.Gui.csproj
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.6.2-build5373-beta" />
+ <PackageReference Include="QrCode.Net" Version="0.4.0" />
</ItemGroup>
<ItemGroup>

New QR Code control for Avalonia