我試圖模仿Windows 7中的粘滯便箋應用程序。在原始應用程序中,如果您將文本輸入便箋並且文本變得太大(垂直,如數字),以適應窗口,窗口會自動垂直擴展,一次一行,以留出更多空間。換句話說,在普通文本框中出現一個垂直滾動條並且文本向下滾動(以便第一行變爲不可見),在粘滯便箋中,文本框展開得足夠精確以適應文本,從而不出現滾動條。當然,當您手動調整窗口大小時,滾動條仍然會出現。文本太長時自動垂直擴展文本框
如果您有Windows 7,只需打開粘滯便箋應用程序並在粘滯便箋中鍵入幾行直到它放大。
我想模仿這種效果,但我沒有運氣。問題似乎是,實際的窗口應該調整大小,而不僅僅是文本框(我不認爲WPF以這種方式工作,調整子元素的大小可以'強制'父元素變得更大?至少不是一個窗口,對?)。
窗口在這一點上的內容是這樣的:
<Window Background="Transparent" BorderBrush="Transparent">
<!-- Transparent border to draw dropshadow on -->
<Border Background="Transparent" BorderBrush="Transparent">
<!-- Grid with UI elements -->
<Grid Margin="5" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="27" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Stickynote header -->
<Border ... />
<!-- Content -->
<Border Grid.Row="1">
<TextBox Text="{Binding ContentText}" ... />
</Border>
</Grid>
</Border>
</Window>
有誰知道我怎麼可以達到這個效果?謝謝!
嘗試設置寬度=「自動」爲文本框 – sll