【问题标题】:Setting Window in WPF to the bottom right将WPF中的窗口设置为右下角
【发布时间】:2020-11-14 00:57:21
【问题描述】:

我正在尝试将我的窗口设置在左下角。 窗口没有标题栏,height 设置为autoSizeToContentHeightWindowStartupLocationManual

设置内容后我正在执行这两行代码:

Left = SystemParameters.WorkArea.Width - Width - 2; 
Top = SystemParameters.WorkArea.Height - Height - 2;

这两行在 SetupWindow() 函数中

InitializeComponent();            

            foreach (Caller c in callers)
            {
                CallerLine callerline = new CallerLine();
                Hyperlink link = (Hyperlink)callerline.FindName("link");
                ContentControl ccname = (ContentControl)callerline.FindName("ccname");
                ContentControl ccnumber = (ContentControl)callerline.FindName("ccnumber");                

                link.RequestNavigate += hyperlink_RequestNavigate;
                ccname.Content = c.Name;
                ccnumber.Content = " " + c.PhoneNumber;

                spCallers.Children.Add(callerline);
            }

            SetupWindow();

在将窗口设置到新位置之前,我正在完成所有设置工作!

现在窗口设置在屏幕右侧的某个位置,而不是底部。如何将其设置为右下角?

【问题讨论】:

标签: c# wpf


【解决方案1】:

解决方案是在触发 ContentRendered 时设置位置。这里是代码:

private void Window_ContentRendered(object sender, EventArgs e)
{
    Left = SystemParameters.WorkArea.Width - Width - 2;
    Top = SystemParameters.WorkArea.Height - Height - 2;
}

【讨论】:

    猜你喜欢
    • 2020-02-07
    • 2011-11-29
    • 2016-06-23
    • 1970-01-01
    • 2017-01-27
    • 2012-09-17
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多