simplify API more
MODIFY
WalletWasabi.Fluent/App.xaml
WalletWasabi.Fluent/App.xaml
<StyleInclude Source="avares://WalletWasabi.Fluent/Styles/Themes/BaseDark.xaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Icons/Icons.xaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Styles/Styles.xaml" />
- <StyleInclude Source="avares://WalletWasabi.Fluent/Controls/DialogContentHost.xaml" />
+ <StyleInclude Source="avares://WalletWasabi.Fluent/Controls/Dialog.xaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Controls/NavBarItem.xaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Controls/NavBarTreeItem.xaml" />
</Application.Styles>

RENAME
WalletWasabi.Fluent/Controls/DialogContentHost.xaml
WalletWasabi.Fluent/Controls/Dialog.xaml
</Design.PreviewWith>
<Styles.Resources>
</Styles.Resources>
- <Style Selector="c|DialogContentHost">
+ <Style Selector="c|Dialog">
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Panel Background="#272727" Name="PART_Overlay">
- <Button Classes="invisible" Command="{TemplateBinding CloseDialogCommand}"/>
+ <Button Name="PART_OverlayButton" Classes="invisible" />
</Panel>
<Panel Name="PART_DialogHost" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border CornerRadius="5" BoxShadow="4 11 30 1 #90000000" Background="#323232" >
</ControlTemplate>
</Setter>
</Style>
- <Style Selector="c|DialogContentHost /template/ Panel#PART_Overlay">
+ <Style Selector="c|Dialog /template/ Panel#PART_Overlay">
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.25" />
<Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="Opacity" Value="0"/>
</Style>
- <Style Selector="c|DialogContentHost /template/ Panel#PART_DialogHost">
+ <Style Selector="c|Dialog /template/ Panel#PART_DialogHost">
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.35" Easing="0.1,0.9,0.2,1.0" />
<Setter Property="Opacity" Value="0"/>
</Style>
- <Style Selector="c|DialogContentHost:open /template/ Panel#PART_DialogHost">
+ <Style Selector="c|Dialog[IsDialogOpen=true] /template/ Panel#PART_DialogHost">
<Setter Property="RenderTransform" Value="scaleX(1) scaleY(1)" />
<Setter Property="Opacity" Value="1"/>
<Setter Property="IsHitTestVisible" Value="True"/>
</Style>
- <Style Selector="c|DialogContentHost:not(:open) /template/ Panel#PART_DialogHost">
+ <Style Selector="c|Dialog[IsDialogOpen=false] /template/ Panel#PART_DialogHost">
<Setter Property="RenderTransform" Value="scaleX(0.9) scaleY(0.9)" />
<Setter Property="Opacity" Value="0"/>
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
- <Style Selector="c|DialogContentHost:open /template/ Panel#PART_Overlay">
+ <Style Selector="c|Dialog[IsDialogOpen=true] /template/ Panel#PART_Overlay">
<Setter Property="IsHitTestVisible" Value="True"/>
<Setter Property="Opacity" Value="0.8"/>
</Style>
- <Style Selector="c|DialogContentHost:not(:open) /template/ Panel#PART_Overlay">
+ <Style Selector="c|Dialog[IsDialogOpen=false] /template/ Panel#PART_Overlay">
<Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="Opacity" Value="0"/>
</Style>

ADD
WalletWasabi.Fluent/Controls/Dialog.xaml.cs
+using System;
+using System.Windows.Input;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using ReactiveUI;
+using WalletWasabi.Fluent.ViewModels.Dialog;
+
+namespace WalletWasabi.Fluent.Controls
+{
+ /// <summary>
+ /// Manages and hosts dialogs when it's bound to <see cref="IContent"/> objects.
+ /// </summary>
+ public class Dialog : ContentControl
+ {
+ public static readonly StyledProperty<bool> IsDialogOpenProperty =
+ AvaloniaProperty.Register<Dialog, bool>(nameof(IsDialogOpen));
+
+ public bool IsDialogOpen
+ {
+ get => GetValue(IsDialogOpenProperty);
+ set => SetValue(IsDialogOpenProperty, value);
+ }
+
+ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
+ {
+ base.OnApplyTemplate(e);
+
+ var overlayButton = e.NameScope.Find<Button>("PART_OverlayButton");
+ overlayButton.Click += delegate { IsDialogOpen = false; };
+ }
+ }
+}

DELETE
WalletWasabi.Fluent/Controls/DialogContentHost.cs
-using System;
-using System.Windows.Input;
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Controls.Primitives;
-using ReactiveUI;
-using WalletWasabi.Fluent.ViewModels.Dialog;
-
-namespace WalletWasabi.Fluent.Controls
-{
- /// <summary>
- /// Manages and hosts dialogs when it's bound to <see cref="IContent"/> objects.
- /// </summary>
- public class DialogContentHost : TemplatedControl
- {
- public static readonly StyledProperty<DialogViewModelBase> ContentProperty =
- AvaloniaProperty.Register<DialogContentHost, DialogViewModelBase>(nameof(Content));
-
- public static readonly StyledProperty<ICommand> CloseDialogCommandProperty =
- AvaloniaProperty.Register<DialogContentHost, ICommand>(nameof(CloseDialogCommand));
-
- static DialogContentHost()
- {
- ContentProperty.Changed.AddClassHandler<DialogContentHost>(OnContentPropertyChanged);
- }
-
- public DialogContentHost()
- {
- CloseDialogCommand = ReactiveCommand.Create(() => Content?.CloseDialog());
- }
-
- /// <summary>
- /// Gets or sets the VM that implements <see cref="IContent"/>
- /// </summary>
- public DialogViewModelBase Content
- {
- get => GetValue(ContentProperty);
- set => SetValue(ContentProperty, value);
- }
-
- public ICommand CloseDialogCommand
- {
- get => GetValue(CloseDialogCommandProperty);
- set => SetValue(CloseDialogCommandProperty, value);
- }
-
- private static void OnContentPropertyChanged(DialogContentHost arg1, AvaloniaPropertyChangedEventArgs arg2)
- {
- (arg2.NewValue as DialogViewModelBase)?.WhenAnyValue(x => x.IsDialogOpen).Subscribe(x =>
- {
- arg1.PseudoClasses.Set(":open", x);
- });
- }
- }
-}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase.cs
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase.cs
@@ -18,17 +18,11 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
set => this.RaiseAndSetIfChanged(ref _isDialogOpen, value);
}
- /// <summary>
- /// Method that is triggered when the dialog
- /// is to be shown.
- /// </summary>
- protected abstract void DialogShowing();
-
/// <summary>
/// Method that is triggered when the dialog
/// is about to close.
/// </summary>
- protected abstract void DialogClosing();
+ protected abstract void OnDialogClosed();
/// <summary>
/// Method to be called when the dialog intends to close
@@ -41,8 +35,8 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
throw new InvalidOperationException("Dialog was already closed.");
}
- DialogClosing();
IsDialogOpen = false;
+ OnDialogClosed();
}
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBaseOfTResult.cs
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBaseOfTResult.cs
@@ -18,6 +18,11 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
/// <param name="value">The return value of the dialog</param>
public void CloseDialog(TResult value)
{
+ if (CurrentTaskCompletionSource is null)
+ {
+ throw new InvalidOperationException("CloseDialog with value return method failed due to missing TCS.");
+ }
+
CurrentTaskCompletionSource.SetResult(value);
CurrentTaskCompletionSource = null;
@@ -39,8 +44,6 @@ namespace WalletWasabi.Fluent.ViewModels.Dialog
CurrentTaskCompletionSource = new TaskCompletionSource<TResult>();
- DialogShowing();
-
IsDialogOpen = true;
return CurrentTaskCompletionSource.Task;

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -75,22 +75,5 @@ namespace WalletWasabi.Fluent.ViewModels
Title += $" - {Network}";
}
}
-
- // void IDialogHost.ShowDialog<TDialog>(TDialog dialogViewModel)
- // {
- // var dialogHost = (this as IDialogHost);
- // dialogHost.CurrentDialog = dialogViewModel;
- // DialogStateListener(true);
- // }
-
- // void IDialogHost.CloseDialog()
- // {
- // DialogStateListener(false);
- // }
-
- // public void SetDialogStateListener(Action<bool> listener)
- // {
- // this.DialogStateListener = listener;
- // }
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/TestDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/TestDialogViewModel.cs
@@ -6,17 +6,8 @@ namespace WalletWasabi.Fluent.ViewModels
{
public class TestDialogViewModel : DialogViewModelBase<string>
{
- protected override void DialogClosing()
+ protected override void OnDialogClosed()
{
}
-
- protected override void DialogShowing()
- {
- Task.Run(async () =>
- {
- await Task.Delay(15000);
- CloseDialog("Done");
- });
- }
}
}

MODIFY
WalletWasabi.Fluent/Views/MainView.axaml
WalletWasabi.Fluent/Views/MainView.axaml
</DockPanel>
</Panel>
</SplitView>
- <c:DialogContentHost Content="{Binding CurrentDialog}"/>
+ <c:Dialog Content="{Binding CurrentDialog}" IsDialogOpen="{Binding CurrentDialog.IsDialogOpen, Mode=TwoWay}"/>
</Panel>
</UserControl>

MODIFY
WalletWasabi.Fluent/Views/TestDialogView.axaml
WalletWasabi.Fluent/Views/TestDialogView.axaml
</Button>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
- <TextBlock Text="Hi, I'm a dialog and will close in 15 seconds!" />
+ <TextBlock Text="Hi, I'm a dialog!" />
</StackPanel>
</Panel>
</UserControl>

simplify API more