fix nullable warnings in behaviors.
MODIFY
WalletWasabi.Fluent/Behaviors/AutoBringIntoViewExtension.cs
WalletWasabi.Fluent/Behaviors/AutoBringIntoViewExtension.cs
@@ -2,6 +2,7 @@ using Avalonia.Controls;
using Avalonia.Input;
using ReactiveUI;
using System.Reactive.Linq;
+using Avalonia.VisualTree;
namespace WalletWasabi.Fluent.Behaviors;
@@ -15,14 +16,17 @@ public static class AutoBringIntoViewExtension
{
Initialised = true;
- KeyboardDevice.Instance.WhenAnyValue(x => x.FocusedElement)
- .OfType<IControl>()
+ if (KeyboardDevice.Instance is { } device)
+ {
+ device.WhenAnyValue(x => x.FocusedElement)
+ .Where(x => x is IControl)
+ .Select(x => x as IControl)
.Subscribe(
x =>
{
- static void BringParentToView(IInputElement ie)
+ static void BringParentToView(IVisual ie)
{
- if (ie.VisualParent is IInputElement parent && parent.IsKeyboardFocusWithin)
+ if (ie.VisualParent is IInputElement { IsKeyboardFocusWithin: true } parent)
{
BringParentToView(parent);
}
@@ -41,3 +45,5 @@ public static class AutoBringIntoViewExtension
}
}
}
+}
+

MODIFY
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnActivated.cs
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnActivated.cs
@@ -20,7 +20,9 @@ public class ExecuteCommandOnActivated : DisposingBehavior<Control>
protected override void OnAttached(CompositeDisposable disposables)
{
- var mainWindow = ((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).MainWindow;
+ if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
+ {
+ var mainWindow = lifetime.MainWindow;
Observable
.FromEventPattern(mainWindow, nameof(mainWindow.Activated))
@@ -34,3 +36,4 @@ public class ExecuteCommandOnActivated : DisposingBehavior<Control>
.DisposeWith(disposables);
}
}
+}

MODIFY
WalletWasabi.Fluent/Behaviors/FocusNextWhenValid.cs
WalletWasabi.Fluent/Behaviors/FocusNextWhenValid.cs
@@ -11,6 +11,8 @@ namespace WalletWasabi.Fluent.Behaviors;
public class FocusNextWhenValid : DisposingBehavior<TextBox>
{
protected override void OnAttached(CompositeDisposable disposables)
+ {
+ if (AssociatedObject is { })
{
var hasErrors = AssociatedObject.GetObservable(DataValidationErrors.HasErrorsProperty);
var text = AssociatedObject.GetObservable(TextBox.TextProperty);
@@ -24,7 +26,8 @@ public class FocusNextWhenValid : DisposingBehavior<TextBox>
if (AssociatedObject is { } &&
!DataValidationErrors.GetHasErrors(AssociatedObject) &&
!string.IsNullOrEmpty(AssociatedObject.Text) &&
- KeyboardNavigationHandler.GetNext(AssociatedObject, NavigationDirection.Next) is { } nextFocus)
+ KeyboardNavigationHandler.GetNext(AssociatedObject, NavigationDirection.Next) is
+ { } nextFocus)
{
nextFocus.Focus();
}
@@ -32,3 +35,4 @@ public class FocusNextWhenValid : DisposingBehavior<TextBox>
.DisposeWith(disposables);
}
}
+}

MODIFY
WalletWasabi.Fluent/Behaviors/NumberBoxBehavior.cs
WalletWasabi.Fluent/Behaviors/NumberBoxBehavior.cs
@@ -35,8 +35,10 @@ public class NumberBoxBehavior : DisposingBehavior<TextBox>
{
e.Handled = true;
- var text = await Application.Current.Clipboard.GetTextAsync();
- AssociatedObject.Text = CorrectInput(text);
+ if (Application.Current is { Clipboard: { } clipboard })
+ {
+ AssociatedObject.Text = CorrectInput(await clipboard.GetTextAsync());
+ }
})
.DisposeWith(disposables);
}

MODIFY
WalletWasabi.Fluent/Behaviors/PasteButtonFlashBehavior.cs
WalletWasabi.Fluent/Behaviors/PasteButtonFlashBehavior.cs
@@ -38,7 +38,7 @@ public class PasteButtonFlashBehavior : AttachedToVisualTreeBehavior<AnimatedBut
{
RxApp.MainThreadScheduler.Schedule(async () => await CheckClipboardForValidAddressAsync());
- if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
+ if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
var mainWindow = lifetime.MainWindow;
@@ -73,7 +73,9 @@ public class PasteButtonFlashBehavior : AttachedToVisualTreeBehavior<AnimatedBut
private async Task CheckClipboardForValidAddressAsync()
{
- var clipboardValue = await Application.Current.Clipboard.GetTextAsync();
+ if (Application.Current is { Clipboard: { } clipboard })
+ {
+ var clipboardValue = await clipboard.GetTextAsync();
if (AssociatedObject is null || _lastFlashedOn == clipboardValue)
{
@@ -95,3 +97,4 @@ public class PasteButtonFlashBehavior : AttachedToVisualTreeBehavior<AnimatedBut
}
}
}
+}

fix nullable warnings in behaviors.