我已經遇到了類似的問題:我想要一個文本區域可以存放我的文字,是能包住它,它填補了其母公司的控制和是可滾動的。
首先,我試圖用的TextBlock有的ScrollViewer,我認爲它的工作,但由於某種原因,我想用一個的FlowDocument而不是用FlowDocumentScrollViewer。後者沒有奏效,我只是無法離開戰鬥,所以我試圖找到解決方案,這就是我如何到達這裏。我試圖將解答中提出的解決方法應用於原始問題,但是這兩種解決方案都不適合我(我使用的是.NET 4.5,也許它適用於其他版本,但我不知道這一點)。
我已經嘗試過使用單獨的FlowDocument本身,但該控件包含一些我不想要的UI元素。所以,我想出了另一個解決方案。
<ScrollViewer VerticalScrollBarVisibility="Auto">
<FlowDocumentScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<FlowDocument>
沒錯。有用!調用ScrollViewer.ScrollToBottom()只是工作! ScrollViewer啓用滾動和FlowDocumentScrollViewer從FlowDocument中刪除UI元素。希望能幫助到你!
顯然,我的建設有一個缺陷,因爲這種方式的FlowDocument不是通過鼠標的滾輪滾動。但是設置FlowDocumentScrollViewer控制的IsHitTestVisible屬性到錯誤解決此問題。
感謝您指出我的答案中的錯誤。我糾正了它。 – 2009-04-01 18:21:13