0
我有一個ScrollViewer嵌入到另一個ScrollViewer的設計。 我有的問題是,子ScrollViewer不填充其父,但始終使父ScrollViewer滾動。 我需要給孩子ScrollViewer只有它父母的空間,然後讓孩子滾動,如果它的內容太大,不適合。如何讓子ScrollViewer在另一個(父級)ScrollViewer填充其父母
我知道有一個simmilar問題,但它並不能幫助我: Use ScrollViewer inside another Scrollviewer
這裏是顯示問題的代碼:
<Window
x:Class="ScrollviewerIssue.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="200"
Height="200"
mc:Ignorable="d">
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Row="1" Grid.Column="1">
<TextBox TextWrapping="Wrap">
Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text
</TextBox>
</ScrollViewer>
</Grid>
</ScrollViewer>
</Window>
爲什麼,如果你不使用它的滾動功能使用的ScrollViewer?如果父級的滾動功能未使用,則將其完全刪除。 –
爲簡單起見,此示例已修剪。在真實場景中還有許多其他元素,這使得使用兩個ScrollViewer都非常有用。 – kodieren
在這種情況下,你必須指定你的孩子ScrollViewer的大小。你可以通過設置它的高度和寬度來做到這一點,或者你可以給你的RowDefinition和ColumnDefinition特定的高度和寬度... –