調整畫布父級的大小時,出現奇怪的問題,這恰好是ChildWindow。在Silverlight中動態調整ChildWindow高度會導致奇怪的行爲
從一個高的水平,這就是我想要當用戶點擊一個按鈕做的事:
- 取消隱藏行,從0設置RowDefinition高度更大的東西。
- 調整畫布大小,因爲裏面的東西都比較高。
- 調整畫布的父項(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像素,92個像素的又一個空的空間後,被添加到ChildWindow標題欄下用戶單擊該按鈕。更重要的是,當用戶再次單擊按鈕(切換行可見性)時,該行消失,但窗口頂部的額外空間仍然存在。最初,這個空的空間不在那裏。看到這個圖片:
任何想法/幫助將不勝感激。謝謝!
不幸的是,RowDefinition不具有可見光/ ISVISIBLE/Visibility屬性。此外,當我隱藏網格行的所有內容時,它不會調整爲無(或隱藏自己)。據我所知,沒有真正的「行」對象,我可以把我的表單域...我必須分配每個單獨的字段的Grid.Row。我想我可能不得不重做所有東西,把我的田地分成可以隱藏的子網格。 – 2010-11-16 16:56:38