我发现了这个问题。在我上面的XAML中
<Grid Margin="5" x:Name="canvas1" ClipToBounds="True" VerticalAlignment="Top">
随着 VerticalAlignment="Top" 并且高度(隐式)设置为自动我告诉系统通过测量内容来设置网格垂直大小。我不完全确定为什么这给出了我看到的效果,但显然不是我想要的。我想要的是Grid填充DockPanel中的可用空间,然后告诉我的ViewModel这个大小是多少。
VerticalAlignment="Top"
解决方案很简单:删除 VerticalAlignment="Top" 隐含地设定 VerticalAlignment="Stretch" 现在它完全符合我的要求。
VerticalAlignment="Stretch"