Fix window position on macOS
This commit is contained in:
parent
8caed1f4d2
commit
c345223fdc
src
@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
|
||||
@ -20,6 +21,17 @@ namespace AvaloniaCoreRTDemo
|
||||
return new Bitmap(assetStream);
|
||||
}
|
||||
|
||||
public static PixelPoint GetWindowPosition(Window window)
|
||||
{
|
||||
if (!IsOSX || !window.FrameSize.HasValue)
|
||||
return window.Position;
|
||||
else
|
||||
{
|
||||
Int32 yOffset = (Int32)(window.FrameSize.Value.Height - window.ClientSize.Height);
|
||||
return new(window.Position.X, window.Position.Y + yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap GetImageFromFile(String path)
|
||||
{
|
||||
try
|
||||
|
@ -1,48 +1,48 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
using AvaloniaCoreRTDemo.Controls;
|
||||
using AvaloniaCoreRTDemo.Interfaces;
|
||||
using AvaloniaCoreRTDemo.Windows.ViewModels;
|
||||
|
||||
namespace AvaloniaCoreRTDemo.Windows
|
||||
{
|
||||
public sealed partial class MainWindow : Window, IMainWindow
|
||||
{
|
||||
private readonly Application? _app = App.Current;
|
||||
|
||||
private MainControl MainControl => this.GetControl<MainControl>("MainControl");
|
||||
|
||||
using AvaloniaCoreRTDemo.Controls;
|
||||
using AvaloniaCoreRTDemo.Interfaces;
|
||||
using AvaloniaCoreRTDemo.Windows.ViewModels;
|
||||
|
||||
namespace AvaloniaCoreRTDemo.Windows
|
||||
{
|
||||
public sealed partial class MainWindow : Window, IMainWindow
|
||||
{
|
||||
private readonly Application? _app = App.Current;
|
||||
|
||||
private MainControl MainControl => this.GetControl<MainControl>("MainControl");
|
||||
|
||||
public MainWindow() : this(default) { }
|
||||
public MainWindow(IMainWindow? window)
|
||||
{
|
||||
this.InitializeComponent(window);
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
IThemeSwitch IMainWindow.ThemeSwitch => (IThemeSwitch)this._app!;
|
||||
IMainWindowState IMainWindow.Model => (IMainWindowState)this.MainControl.DataContext!;
|
||||
PixelPoint IMainWindow.Position => this.Position;
|
||||
Size IMainWindow.ClientSize => this.ClientSize;
|
||||
Size? IMainWindow.FrameSize => this.FrameSize;
|
||||
WindowState IMainWindow.State => this.WindowState;
|
||||
|
||||
private void InitializeComponent(IMainWindow? window)
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
this.DataContext = new MainViewModel<MainWindow>(this);
|
||||
if (window is not null)
|
||||
{
|
||||
this.MainControl.Reload(window.Model);
|
||||
this.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
this.WindowState = window.State;
|
||||
this.Position = window.Position;
|
||||
this.FrameSize = window.FrameSize;
|
||||
this.ClientSize = window.ClientSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public MainWindow(IMainWindow? window)
|
||||
{
|
||||
this.InitializeComponent(window);
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
IThemeSwitch IMainWindow.ThemeSwitch => (IThemeSwitch)this._app!;
|
||||
IMainWindowState IMainWindow.Model => (IMainWindowState)this.MainControl.DataContext!;
|
||||
PixelPoint IMainWindow.Position => Utilities.GetWindowPosition(this);
|
||||
Size IMainWindow.ClientSize => this.ClientSize;
|
||||
Size? IMainWindow.FrameSize => this.FrameSize;
|
||||
WindowState IMainWindow.State => this.WindowState;
|
||||
|
||||
private void InitializeComponent(IMainWindow? window)
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
this.DataContext = new MainViewModel<MainWindow>(this);
|
||||
if (window is not null)
|
||||
{
|
||||
this.MainControl.Reload(window.Model);
|
||||
this.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
this.WindowState = window.State;
|
||||
this.Position = window.Position;
|
||||
this.FrameSize = window.FrameSize;
|
||||
this.ClientSize = window.ClientSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user