当我调整一个画布的父元素大小时,遇到了一个奇怪的问题,这个父元素恰好是一个ChildWindow。
从高层次上讲,当用户点击一个按钮时,我要做的事情如下:
- 通过将RowDefinition的高度从0设置为更大的值来取消隐藏一行。
- 调整画布的大小,因为里面的所有内容都更高了。
- 调整画布的父级元素(即ChildWindow),因为画布更高了。
步骤1和2正常工作。问题出在第3步:当我在F# / Silverlight代码中进行步进时,所有尺寸似乎都被正确设置了。问题在于,ChildWindow在屏幕上呈现出比它实际应该的要高得多的样子。
看下面的示例:
member this.btnWhatever_Click(sender : obj) (args : RoutedEventArgs) =
let parentWindow = this.Parent :?> ChildWindow // get the canvas' parent, and cast it to a ChildWindow
// if the RowDefinition height is set to our standard, the hide it by setting it to 0
if this.aRowDefinition.Height.Value.Equals STANDARD_ROW_HEIGHT then
this.aRowDefinition.Height <- new GridLength(0.)
this.Height <- this.Height - HEDGE_ROW_HEIGHT
parentWindow.Height <- parentWindow.Height - STANDARD_ROW_HEIGHT
this.btnCreateOrRemoveHedge.Content <- "On"
// otherwise, unhide the RowDefinition by setting it to the standard height
else
this.aRowDefinition.Height <- new GridLength(STANDARD_ROW_HEIGHT)
this.Height <- this.Height + STANDARD_ROW_HEIGHT
parentWindow.Height <- parentWindow.Height + STANDARD_ROW_HEIGHT
this.btnWhatever.Content <- "Off"
()
在这种情况下,我的STANDARD_ROW_HEIGHT只有23像素,但是用户单击按钮后,在标题栏下方的ChildWindow中添加了92个像素的空白空间。更重要的是,当用户再次单击按钮(切换行可见性)时,行消失但窗口顶部的额外空间仍然存在。最初,这个空白空间并不存在。请参见此图像:
任何想法/帮助将不胜感激。谢谢!