Avalonia框架固定页面位置和判断横屏竖屏

Avalonia是个跨平台的框架,具体的更多基本知识我就不在赘述。Avalonia框架的功能和WPF的功能基本相似,很多写法也可以套用,但是还是有很多细节不一致的,这就需要再运用中总结。本文主要是描述Avalonia页面怎么固定位置和判断当前屏幕是横屏还是竖屏。

判断当前屏幕是横屏还是竖屏主要是通过获取屏幕的宽和高来实现:

Avalonia横屏;

Screens.Primary.Bounds.Width> Screens.Primary.Bounds.Height

Avalonia竖屏;

Screens.Primary.Bounds.Width < Screens.Primary.Bounds.Height

WPF横屏;

Screen.PrimaryScreen.Bounds.Width > Screen.PrimaryScreen.Bounds.Height

WPF竖屏;

Screen.PrimaryScreen.Bounds.Width < Screen.PrimaryScreen.Bounds.Height

Avalonia固定窗口位置位置:

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Window_Loaded("", null);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Screen[] screens = Screens.All.ToArray();
            foreach (var s in screens)
            {
                
                if (s.Primary == false)
                {
                    this.WindowState = WindowState.Normal;
                    this.WindowStartupLocation = WindowStartupLocation.Manual;
                    this.Position = new Avalonia.PixelPoint(s.Bounds.X, s.Bounds.Y);
                }
            }
        }
    }

WPF固定窗口位置位置:

  this.StartPosition = FormStartPosition.Manual;
            this.Left = s.Bounds.X;
            this.Top = s.Bounds.Y;

Avalonia和WPF的具体位置可以在上文中的  s.Bounds.X 和 s.Bounds.Y 后加具体的值,根据自己的需求进行调整。

如果需要居中显示的话:

Avalonia:

WindowStartupLocation = WindowStartupLocation.CenterScreen;

WPF:

StartPosition = FormStartPosition.CenterScreen;
WindowStartupLocation = WindowStartupLocation.CenterScreen;

希望可以帮助正在寻找这个问题解决方法的人。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值