No need to use UI resources as a poor mans locator...
MODIFY
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
@@ -7,6 +7,7 @@ using Avalonia.Xaml.Interactivity;
using NBitcoin;
using NBitcoin.Payment;
using ReactiveUI;
+using Splat;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
@@ -75,7 +76,7 @@ namespace WalletWasabi.Gui.Behaviors
public PasteAddressOnClickBehavior()
{
- Global = Application.Current.Resources[Global.GlobalResourceKey] as Global;
+ Global = Locator.Current.GetService<Global>();
}
protected override void OnAttached()

MODIFY
WalletWasabi.Gui/Controls/MultiTextBox.cs
WalletWasabi.Gui/Controls/MultiTextBox.cs
@@ -7,6 +7,7 @@ using Avalonia.Input;
using Avalonia.Styling;
using Avalonia.Threading;
using ReactiveUI;
+using Splat;
using System;
using System.Reactive;
using System.Reactive.Disposables;
@@ -191,7 +192,7 @@ namespace WalletWasabi.Gui.Controls
try
{
var eventArgs = eventPattern?.EventArgs as PointerPressedEventArgs;
- var uiConfig = Application.Current.Resources[Global.UiConfigResourceKey] as UiConfig;
+ var uiConfig = Locator.Current.GetService<Global>().UiConfig;
if (uiConfig?.Autocopy is true && eventArgs?.GetCurrentPoint(this).Properties.IsLeftButtonPressed == true)
{
if (CopyOnClick)

MODIFY
WalletWasabi.Gui/Converters/LurkingWifeModeStringConverter.cs
WalletWasabi.Gui/Converters/LurkingWifeModeStringConverter.cs
using Avalonia;
using Avalonia.Data.Converters;
using NBitcoin;
+using Splat;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -13,7 +14,7 @@ namespace WalletWasabi.Gui.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
- var uiConfig = Application.Current.Resources[Global.UiConfigResourceKey] as UiConfig;
+ var uiConfig = Locator.Current.GetService<Global>().UiConfig;
if (uiConfig.LurkingWifeMode is true)
{
int len = 10;

MODIFY
WalletWasabi.Gui/Converters/PhaseColorConverter.cs
WalletWasabi.Gui/Converters/PhaseColorConverter.cs
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
+using Splat;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -17,7 +18,8 @@ namespace WalletWasabi.Gui.Converters
{
throw new ArgumentException($"Unknown '{parameter}' value");
}
- var global = Application.Current.Resources[Global.GlobalResourceKey] as Global;
+
+ var global = Locator.Current.GetService<Global>();
var phaseError = global.ChaumianClient.State.IsInErrorState;
return (RoundPhase)p <= (RoundPhase)value

MODIFY
WalletWasabi.Gui/Converters/PrivacyLevelValueConverter.cs
WalletWasabi.Gui/Converters/PrivacyLevelValueConverter.cs
@@ -2,6 +2,7 @@ using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
using AvalonStudio.Commands;
+using Splat;
using System;
using System.Collections.Generic;
using System.Composition;
@@ -37,7 +38,7 @@ namespace WalletWasabi.Gui.Converters
{
if (value is int integer)
{
- var config = Application.Current.Resources[Global.ConfigResourceKey] as Config;
+ var config = Locator.Current.GetService<Global>().Config;
string shield;
string toolTip = null;
if (integer < config.PrivacyLevelSome)

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -40,10 +40,6 @@ namespace WalletWasabi.Gui
{
public class Global
{
- public const string GlobalResourceKey = "Wasabi.Ui.Global";
- public const string ConfigResourceKey = "Wasabi.Ui.Config";
- public const string UiConfigResourceKey = "Wasabi.Ui.UiConfig";
-
public const string ThemeBackgroundBrushResourceKey = "ThemeBackgroundBrush";
public const string ApplicationAccentForegroundBrushResourceKey = "ApplicationAccentForegroundBrush";

MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -36,6 +36,8 @@ namespace WalletWasabi.Gui
public MainWindow()
{
+ Global = Locator.Current.GetService<Global>();
+
InitializeComponent();
#if DEBUG
this.AttachDevTools();
@@ -51,7 +53,7 @@ namespace WalletWasabi.Gui
Locator.CurrentMutable.RegisterConstant<INotificationManager>(notificationManager);
}
- public Global Global => MainWindowViewModel.Instance.Global;
+ public Global Global { get; }
private void InitializeComponent()
{
@@ -70,7 +72,6 @@ namespace WalletWasabi.Gui
try
{
Global.InitializeUiConfig(uiConfig);
- Application.Current.Resources.AddOrReplace(Global.UiConfigResourceKey, Global.UiConfig);
Logger.LogInfo($"{nameof(Global.UiConfig)} is successfully initialized.");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -94,18 +95,6 @@ namespace WalletWasabi.Gui
onError: ex => Logger.LogError(ex));
}
- protected override void OnDataContextEndUpdate()
- {
- if (Global is null)
- {
- return;
- }
-
- Application.Current.Resources.AddOrReplace(Global.GlobalResourceKey, Global);
- Application.Current.Resources.AddOrReplace(Global.ConfigResourceKey, Global.Config);
- Application.Current.Resources.AddOrReplace(Global.UiConfigResourceKey, Global.UiConfig);
- }
-
private int _closingState;
private async void MainWindow_ClosingAsync(object sender, CancelEventArgs e)

No need to use UI resources as a poor mans locator...