在我的Windows Phone应用程序中,我正在使用richtextbox
<ScrollViewer Margin="0,0,0,0" VerticalAlignment="Top">
<StackPanel Margin="0,0,0,0" Width="Auto" >
<RichTextBox x:Name="Browser" Foreground="Black" Height="Auto" cxi:WebBrowserHelper.Html="{Binding BrowserHtml}" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top" Width="460" Margin="0,0,0,0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" />
</StackPanel>
</ScrollViewer>
但并非所有文字都显示出来。我该如何解决这个问题?
UPDATE1
我把高度= 700后:(见第二张图片)
UPDATE2
<StackPanel Margin="0,0,0,0" Width="480" Orientation="Vertical">
<ScrollViewer Margin="0,0,0,0" VerticalAlignment="Top" Height="1000" >
<StackPanel Margin="0,0,0,0" Width="Auto" >
<RichTextBox x:Name="Browser" Foreground="Black" Height="1000" cxi:WebBrowserHelper.Html="{Binding BrowserHtml}" Background="Transparent" HorizontalAlignment="Left" Width="460" Margin="0,0,0,0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" />
</StackPanel>
</ScrollViewer>
</StackPanel>
答案 0 :(得分:2)
问题不在于RichTextBox,它是由您使用StackPanels引起的。 下面的示例使用简单的矩形重现问题/解决方案。
垂直方向的StackPanel扩展到内容的大小。这意味着它内部的ScrollViewer无法正确拉伸以适应。要使ScrollViewer工作,它必须是固定大小。
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Margin="0,0,0,0" Width="480" Orientation="Vertical">
<ScrollViewer Margin="0,0,0,0" VerticalAlignment="Stretch">
<StackPanel Margin="0,0,0,0" Width="Auto" >
<Rectangle Fill="Aqua" Height="200"/>
<Rectangle Fill="Red" Height="200"/>
<Rectangle Fill="Yellow" Height="200"/>
<Rectangle Fill="Blue" Height="200"/>
<Rectangle Fill="Green" Height="200"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Grid>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Margin="0,0,0,0" VerticalAlignment="Stretch" >
<StackPanel Margin="0,0,0,0" Width="Auto" >
<Rectangle Fill="Aqua" Height="200"/>
<Rectangle Fill="Red" Height="200"/>
<Rectangle Fill="Yellow" Height="200"/>
<Rectangle Fill="Blue" Height="200"/>
<Rectangle Fill="Green" Height="200"/>
</StackPanel>
</ScrollViewer>
</Grid>
答案 1 :(得分:1)
您必须在RichTextBox中设置height =“auto”。以下代码适用于我:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Margin="0,0,0,0" VerticalAlignment="Stretch" >
<RichTextBox ScrollViewer.VerticalScrollBarVisibility="Visible" Name="richTextBox" Style="{StaticResource RichTextBoxStyle1}" Height="auto"/>
</ScrollViewer>
</Grid>
答案 2 :(得分:0)
使用ScrollViewer时,必须指定它的高度元素(固定或动态,如网格中)。否则它会根据内容占据所有高度,即使它超出了屏幕。 所以试试这样的'ScrollViewer Height =“700”....'