1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Runtime.InteropServices;
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Markup.Xaml;
- using Avalonia.Threading;
- namespace IntegrationTestApp
- {
- public class ShowWindowTest : Window
- {
- private readonly DispatcherTimer? _timer;
- private readonly TextBox? _orderTextBox;
-
- public ShowWindowTest()
- {
- InitializeComponent();
- DataContext = this;
- PositionChanged += (s, e) => this.GetControl<TextBox>("CurrentPosition").Text = $"{Position}";
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {
- _orderTextBox = this.GetControl<TextBox>("CurrentOrder");
- _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) };
- _timer.Tick += TimerOnTick;
- _timer.Start();
- }
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
- protected override void OnOpened(EventArgs e)
- {
- base.OnOpened(e);
- var scaling = PlatformImpl!.DesktopScaling;
- this.GetControl<TextBox>("CurrentPosition").Text = $"{Position}";
- this.GetControl<TextBox>("CurrentScreenRect").Text = $"{Screens.ScreenFromVisual(this)?.WorkingArea}";
- this.GetControl<TextBox>("CurrentScaling").Text = $"{scaling}";
- if (Owner is not null)
- {
- var ownerRect = this.GetControl<TextBox>("CurrentOwnerRect");
- var owner = (Window)Owner;
- ownerRect.Text = $"{owner.Position}, {PixelSize.FromSize(owner.FrameSize!.Value, scaling)}";
- }
- }
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- _timer?.Stop();
- }
- private void TimerOnTick(object? sender, EventArgs e)
- {
- _orderTextBox!.Text = MacOSIntegration.GetOrderedIndex(this).ToString();
- }
- }
- }
|