gpt4 book ai didi

c# - 将 XAML 中 WPF 窗口的启动位置更改为右下角

转载 作者:行者123 更新时间:2023-11-30 20:20:39 27 4
gpt4 key购买 nike

是否可以将 XAML 中的 WPF 窗口的手动启动位置设置为在屏幕的右下角启动?我可以在代码隐藏中做到这一点,但是当窗口打开时,它会在手动位置(屏幕左中)弹出,然后跳到屏幕右下角,看起来不太好。

我可以使用以下代码在 XAML 中将位置设置在角的左上角:

<Window x:Class="WpfApplication1.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
Height="500" Width="500"
WindowStartupLocation="Manual"
Left="0" Top="0">
</Window>

我可以使用 XAML 编码对屏幕的右下角执行相同的操作以适应任何屏幕尺寸吗?

最佳答案

我认为不可能通过xaml 来设置它。但是,您甚至可以在不会从手动位置跳转的窗口加载之前设置它。

public MainWindow()
{
InitializeComponent();
Left = System.Windows.SystemParameters.WorkArea.Width - Width;
Top = System.Windows.SystemParameters.WorkArea.Height - Height;
}

关于c# - 将 XAML 中 WPF 窗口的启动位置更改为右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35887432/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com