Use TopLevel pointer events to implement EnableCancelOnPressed
MODIFY
WalletWasabi.Fluent/Controls/Dialog.axaml
WalletWasabi.Fluent/Controls/Dialog.axaml
<Border Name="PART_Border"
Background="{DynamicResource RegionColor}"
MaxWidth="{TemplateBinding MaxContentWidth}" MaxHeight="{TemplateBinding MaxContentHeight}">
+ <Panel Name="PART_Dismiss">
<ContentPresenter Name="PART_ContentPresenter" Margin="16 28 16 16"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Padding="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/>
+ </Panel>
</Border>
</Panel>
</Panel>
<Setter Property="IsHitTestVisible" Value="True"/>
</Style>
<Style Selector="c|Dialog:open /template/ Panel#PART_Overlay">
- <Setter Property="IsHitTestVisible" Value="True"/>
<Setter Property="Opacity" Value="1"/>
</Style>
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
<Style Selector="c|Dialog:not(:open) /template/ Panel#PART_Overlay">
- <Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="Opacity" Value="0"/>
</Style>
</Styles>

MODIFY
WalletWasabi.Fluent/Controls/Dialog.axaml.cs
WalletWasabi.Fluent/Controls/Dialog.axaml.cs
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
@@ -12,6 +13,8 @@ namespace WalletWasabi.Fluent.Controls
/// </summary>
public class Dialog : ContentControl
{
+ private Panel? _dismissPanel;
+
public static readonly StyledProperty<bool> IsDialogOpenProperty =
AvaloniaProperty.Register<Dialog, bool>(nameof(IsDialogOpen));
@@ -71,17 +74,11 @@ namespace WalletWasabi.Fluent.Controls
{
base.OnApplyTemplate(e);
- var overlayButton = e.NameScope.Find<Panel>("PART_Overlay");
- overlayButton.PointerPressed += (_, _) =>
- {
- if (EnableCancelOnPressed)
- {
- Close();
- }
- };
+ _dismissPanel = e.NameScope.Find<Panel>("PART_Dismiss");
if (this.GetVisualRoot() is TopLevel topLevel)
{
+ topLevel.AddHandler(PointerPressedEvent, CancelPointerPressed, RoutingStrategies.Tunnel);
topLevel.AddHandler(KeyDownEvent, CancelKeyDown, RoutingStrategies.Tunnel);
}
}
@@ -91,6 +88,18 @@ namespace WalletWasabi.Fluent.Controls
IsDialogOpen = false;
}
+ private void CancelPointerPressed(object? sender, PointerPressedEventArgs e)
+ {
+ if (IsDialogOpen && EnableCancelOnPressed && _dismissPanel is not null)
+ {
+ var point = e.GetPosition(_dismissPanel);
+ if (!_dismissPanel.Bounds.Contains(point))
+ {
+ Close();
+ }
+ }
+ }
+
private void CancelKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Escape && EnableCancelOnEscape)

MODIFY
WalletWasabi.Fluent/Views/MainView.axaml
WalletWasabi.Fluent/Views/MainView.axaml
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<c:Dialog.Styles>
- <Style Selector="c|Dialog:open /template/ Panel#PART_Overlay">
- <Setter Property="IsHitTestVisible" Value="False"/>
- </Style>
<Style Selector="c|Dialog /template/ Panel#PART_Overlay">
<Setter Property="Background" Value="{DynamicResource RegionColor}"/>
</Style>
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
MaxContentWidth="800" MaxContentHeight="700">
- <c:Dialog.Styles>
- <Style Selector="c|Dialog:open /template/ Panel#PART_Overlay">
- <Setter Property="IsHitTestVisible" Value="False"/>
- </Style>
- </c:Dialog.Styles>
<ContentControl Content="{Binding CurrentPage}" />
</c:Dialog>
<c:Dialog x:CompileBindings="False"
EnableCancelOnEscape="True"
IsEnabled="{Binding $parent.DataContext.IsDialogScreenEnabled}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
- <c:Dialog.Styles>
- <Style Selector="c|Dialog:open /template/ Panel#PART_Overlay">
- <Setter Property="IsHitTestVisible" Value="False"/>
- </Style>
- </c:Dialog.Styles>
<ContentControl Content="{Binding CurrentPage}" />
</c:Dialog>
</Panel>

Use TopLevel pointer events to implement EnableCancelOnPressed