only detect window monitor when it opens.
MODIFY
WalletWasabi.Gui/Behaviors/BindWindowSizeBehavior.cs
WalletWasabi.Gui/Behaviors/BindWindowSizeBehavior.cs
@@ -3,6 +3,7 @@ using Avalonia.Controls;
using Avalonia.Xaml.Interactivity;
using System;
using System.Linq;
+using System.Reactive.Disposables;
using System.Reactive.Linq;
namespace WalletWasabi.Gui.Behaviors
@@ -10,6 +11,7 @@ namespace WalletWasabi.Gui.Behaviors
public class BindWindowSizeBehavior : Behavior<Window>
{
private Size _maxSize;
+ private CompositeDisposable _disposables;
/// <summary>
/// Defines the <see cref="Width"/> property.
@@ -45,29 +47,36 @@ namespace WalletWasabi.Gui.Behaviors
{
base.OnAttached();
- var screen = AssociatedObject.Screens.ScreenFromPoint(AssociatedObject.Position);
+ _disposables?.Dispose();
+
+ _disposables = new CompositeDisposable();
+
+ Observable.FromEventPattern(AssociatedObject, nameof(AssociatedObject.Opened))
+ .Subscribe(_ => AssociatedObject_Opened())
+ .DisposeWith(_disposables);
+ }
+
+ protected override void OnDetaching()
+ {
+ base.OnDetaching();
+
+ _disposables?.Dispose();
+ _disposables = null;
+ }
+
+ private void AssociatedObject_Opened()
+ {
+ var screen = AssociatedObject.Screens.ScreenFromVisual(AssociatedObject);
_maxSize = screen.WorkingArea.Size.ToSize(screen.PixelDensity) * 0.95;
this.GetObservable(HeightProperty)
.Where(x => !double.IsNaN(x))
- .Subscribe(x =>
- {
- if (x >= _maxSize.Height)
- {
- AssociatedObject.Height = _maxSize.Height;
- }
- });
+ .Subscribe(x => AssociatedObject.Height = x >= _maxSize.Height ? _maxSize.Height : x);
this.GetObservable(WidthProperty)
.Where(x => !double.IsNaN(x))
- .Subscribe(x =>
- {
- if (x >= _maxSize.Width)
- {
- AssociatedObject.Width = _maxSize.Width;
- }
- });
+ .Subscribe(x => AssociatedObject.Width = x >= _maxSize.Width ? _maxSize.Width : x);
}
}
}

only detect window monitor when it opens.