Simplify `FlyoutShowController`
MODIFY
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
WalletWasabi.Fluent/Behaviors/ShowAttachedFlyoutWhenFocusedBehavior.cs
@@ -57,14 +57,14 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : AttachedToVisualTreeBehavio
// If you don't close it, the Flyout will show in an incorrect position. Maybe bug in Avalonia?
if (IsFlyoutOpen)
{
- controller.SetIsOpen(false);
+ controller.SetIsForcedOpen(false);
}
}
private static IDisposable DeactivateCloser(Control visualRoot, FlyoutShowController controller)
{
return Observable.FromEventPattern(visualRoot, nameof(Window.Deactivated))
- .Do(_ => controller.SetIsOpen(false))
+ .Do(_ => controller.SetIsForcedOpen(false))
.Subscribe();
}
@@ -72,14 +72,14 @@ public class ShowAttachedFlyoutWhenFocusedBehavior : AttachedToVisualTreeBehavio
{
return Observable.FromEventPattern(visualRoot, nameof(Window.Activated))
.Where(_ => associatedObject.IsFocused)
- .Do(_ => controller.SetIsOpen(true))
+ .Do(_ => controller.SetIsForcedOpen(true))
.Subscribe();
}
private IDisposable IsOpenPropertySynchronizer(FlyoutShowController controller)
{
return this.WhenAnyValue(x => x.IsFlyoutOpen)
- .Do(controller.SetIsOpen)
+ .Do(controller.SetIsForcedOpen)
.Subscribe();
}

MODIFY
WalletWasabi.Fluent/Helpers/FlyoutShowController.cs
WalletWasabi.Fluent/Helpers/FlyoutShowController.cs
@@ -9,7 +9,6 @@ public class FlyoutShowController : IDisposable
private readonly FlyoutBase _flyout;
private readonly Control _parent;
private bool _isForcedOpen;
- private bool _isOpen;
public FlyoutShowController(Control parent, FlyoutBase flyout)
{
@@ -17,29 +16,7 @@ public class FlyoutShowController : IDisposable
_parent = parent;
}
- public void Dispose()
- {
- _flyout.Closing -= RejectClose;
- }
-
- public void SetIsOpen(bool value)
- {
- if (_isOpen == value)
- {
- return;
- }
-
- Toggle(value);
-
- _isOpen = value;
- }
-
- private static void RejectClose(object? sender, CancelEventArgs e)
- {
- e.Cancel = true;
- }
-
- private void Toggle(bool value)
+ public void SetIsForcedOpen(bool value)
{
if (_isForcedOpen == value)
{
@@ -59,4 +36,14 @@ public class FlyoutShowController : IDisposable
_flyout.Hide();
}
}
+
+ private static void RejectClose(object? sender, CancelEventArgs e)
+ {
+ e.Cancel = true;
+ }
+
+ public void Dispose()
+ {
+ _flyout.Closing -= RejectClose;
+ }
}

Simplify `FlyoutShowController`