【发布时间】:2020-03-14 13:32:45
【问题描述】:
【问题讨论】:
-
欢迎来到 SO!请阅读“How to Ask”及其链接页面以及“Why not upload images of code on SO when asking a question?”和“Discourage screenshots of code and/or errors”。图像对我们帮助不大。请编辑您的问题并提供更多信息。
【问题讨论】:
首先要做的是:我建议使用Window.ActualWidth,因为这将为您提供渲染窗口实际占用的大小,而Window.Width 只为您提供窗口从布局系统请求的大小。
无论如何,这不会解决您的问题。这里的问题是窗口的宽度既包含窗口客户区的宽度,也包含其非客户区的宽度,比如边框(还有一些我不太了解的东西)。
因此,您可以尝试将第二个窗口与第一个窗口的客户区对齐,并考虑窗口边框宽度,如下所示:
window.Left = this.Left
+ (this.Content as FrameworkElement).ActualWidth
+ 2 * SystemParameters.BorderWidth;
【讨论】: