我想要做的是展示一个没有明确高度/宽度的窗口(两个值都被省略或设置为Auto
)。
我猜测这个窗口会通过自动计算所有包含的用户控件大小来确定其大小,但是实际上这并不起作用!
相反,我得到了一个大窗口,Actualwidth
和 Actualheight
值都设置为512(?!?)
窗口声明:
<Window x:Class="Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3"
Height="Auto">
<StackPanel>
<Label>Window</Label>
</StackPanel>
</Window>
通过以下方式将此窗口显示为对话框:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
Dim dlg As New Window3
dlg.ShowDialog()
End Sub
有没有解决方案? 我不想显式设置窗口大小,因为表单中的许多控件将根据构造函数参数折叠,而尝试找到表单的实际大小会很棘手(而且难看)。
.WindowStartupLocation
设置为"CenterScreen"
。 - Anders Lindén