try to slim down things
MODIFY
WalletWasabi.Fluent/Controls/DialogContentHost.cs
WalletWasabi.Fluent/Controls/DialogContentHost.cs
+using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
+using WalletWasabi.Fluent.ViewModels.Dialog;
namespace WalletWasabi.Fluent.Controls
{
@@ -9,38 +11,29 @@ namespace WalletWasabi.Fluent.Controls
/// </summary>
public class DialogContentHost : TemplatedControl
{
- public static readonly StyledProperty<object> ContentProperty =
- AvaloniaProperty.Register<DialogContentHost, object>(nameof(Content));
-
- public static readonly StyledProperty<bool> IsDialogOpenProperty =
- AvaloniaProperty.Register<DialogContentHost, bool>(nameof(IsDialogOpen));
+ public static readonly StyledProperty<IDialogHost> DialogHostProperty =
+ AvaloniaProperty.Register<DialogContentHost, IDialogHost>(nameof(DialogHost));
static DialogContentHost()
{
- IsDialogOpenProperty.Changed.AddClassHandler<DialogContentHost>(UpdatePseudoClasses);
+ DialogHostProperty.Changed.AddClassHandler<DialogContentHost>(OnDialogHostPropertyChanged);
}
- /// <summary>
- /// The object to be displayed as a dialog.
- /// </summary>
- public object Content
+ private static void OnDialogHostPropertyChanged(DialogContentHost arg1, AvaloniaPropertyChangedEventArgs arg2)
+ {
+ (arg2.NewValue as IDialogHost).SetDialogStateListener(x =>
{
- get => GetValue(ContentProperty);
- set => SetValue(ContentProperty, value);
+ arg1.PseudoClasses.Set(":open", x);
+ });
}
/// <summary>
- /// Gets or sets the activation state of the dialog.
+ /// Gets or sets the VM that implements <see cref="IDialogHost"/>
/// </summary>
- public bool IsDialogOpen
- {
- get => GetValue(IsDialogOpenProperty);
- set => SetValue(IsDialogOpenProperty, value);
- }
-
- private static void UpdatePseudoClasses(DialogContentHost arg1, AvaloniaPropertyChangedEventArgs arg2)
+ public IDialogHost DialogHost
{
- arg1.PseudoClasses.Set(":open", (bool)arg2.NewValue);
+ get => GetValue(DialogHostProperty);
+ set => SetValue(DialogHostProperty, value);
}
}
}

MODIFY
WalletWasabi.Fluent/Controls/DialogContentHost.xaml
WalletWasabi.Fluent/Controls/DialogContentHost.xaml
<Panel Background="#272727" Name="PART_Overlay" />
<Panel Name="PART_DialogHost">
<Border VerticalAlignment="Center" HorizontalAlignment="Center" CornerRadius="5" BoxShadow="4 11 30 1 #90000000" Background="#323232" >
- <ContentPresenter Content="{TemplateBinding Content}"/>
+ <ContentPresenter Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DialogHost.CurrentDialog}"/>
</Border>
</Panel>
</Panel>

MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/IDialogHost.cs
WalletWasabi.Fluent/ViewModels/Dialog/IDialogHost.cs
#nullable enable
+using System;
+
namespace WalletWasabi.Fluent.ViewModels.Dialog
{
/// <summary>
@@ -12,8 +14,6 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
/// </summary>
DialogViewModelBase? CurrentDialog { get; set; }
- bool IsDialogOpen { get; set; }
-
/// <summary>
/// Close the currently displayed dialog.
/// </summary>
@@ -24,5 +24,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
/// </summary>
/// <param name="dialogViewModel">The instance of the Dialog ViewModel to be displayed</param>
void ShowDialog<TDialog>(TDialog dialogViewModel) where TDialog : DialogViewModelBase;
+
+ void SetDialogStateListener(Action<bool> listener);
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -5,6 +5,7 @@ using System.Reactive;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Fluent.ViewModels.Dialog;
using Global = WalletWasabi.Gui.Global;
+using System;
namespace WalletWasabi.Fluent.ViewModels
{
@@ -16,7 +17,6 @@ namespace WalletWasabi.Fluent.ViewModels
private DialogViewModelBase? _currentDialog;
private NavBarViewModel _navBar;
private bool _isDialogOpen;
-
public MainViewModel(Global global)
{
_global = global;
@@ -28,6 +28,8 @@ namespace WalletWasabi.Fluent.ViewModels
NavBar = new NavBarViewModel(this, Router, global.WalletManager, global.UiConfig);
}
+ private Action<bool> DialogStateListener { get; set; }
+
public static MainViewModel Instance { get; internal set; }
public RoutingState Router { get; } = new RoutingState();
@@ -85,12 +87,17 @@ namespace WalletWasabi.Fluent.ViewModels
{
var dialogHost = (this as IDialogHost);
dialogHost.CurrentDialog = dialogViewModel;
- dialogHost.IsDialogOpen = true;
+ DialogStateListener(true);
}
void IDialogHost.CloseDialog()
{
- (this as IDialogHost).IsDialogOpen = false;
+ DialogStateListener(false);
+ }
+
+ public void SetDialogStateListener(Action<bool> listener)
+ {
+ this.DialogStateListener = listener;
}
}
}

MODIFY
WalletWasabi.Fluent/Views/MainWindow.axaml
WalletWasabi.Fluent/Views/MainWindow.axaml
<Panel Margin="{Binding #MainWindow.OffScreenMargin}">
<local:MainView />
- <c:DialogContentHost IsDialogOpen="{Binding IsDialogOpen}" Content="{Binding CurrentDialog}"/>
+ <c:DialogContentHost DialogHost="{Binding .}"/>
</Panel>
</Window>

try to slim down things