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