wpf 当 TextBlock 放置在 ScrollViewer 中时在 TextBlock 上显示边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12444830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Displaying Border on TextBlock when TextBlock placed inside ScrollViewer
提问by Jignesh Thakker
I have WPF application, In one of My WPF form has TextBlock. I placed TextBlock inside ScrollViewer for providing scrolling functionality. I want Border on TextBlock so, I have written following code in XAML.
我有 WPF 应用程序,在我的 WPF 表单之一中有 TextBlock。我将 TextBlock 放在 ScrollViewer 中以提供滚动功能。我想要 TextBlock 上的边框,所以我在XAML.
<ScrollViewer Margin="230,32,12,147">
<Border BorderThickness="1" BorderBrush="Black">
<TextBlock Name="textBlock1"></TextBlock>
</Border>
</ScrollViewer>
With scrollBar GUI displayed like below.
滚动条 GUI 显示如下。


Bottom Border display on scroll down to the TextBlock. User Experience is not good for this design. So, I tried with below code but Border is not displaying.
向下滚动到 TextBlock 时显示底部边框。用户体验不适合这种设计。所以,我尝试了下面的代码,但边框没有显示。
<Border BorderThickness="1" BorderBrush="Black">
<ScrollViewer Margin="230,32,12,147">
<TextBlock Name="textBlock1"></TextBlock>
</ScrollViewer>
</Border>
How I can display Border When TextBlock placed inside ScrollViewer?
当 TextBlock 放置在 ScrollViewer 中时,如何显示边框?
回答by opewix
Set border in ScrollViewer control!
在 ScrollViewer 控件中设置边框!
<ScrollViewer Margin="230,32,12,147" BorderThickness="5">
<TextBlock Name="textBlock1"></TextBlock>
</ScrollViewer>
In properties window, expand Othergroup and set BorderThickness
在属性窗口中,展开Other组并设置BorderThickness
Next code works well:
下一个代码运行良好:
<ScrollViewer Height="116" Margin="115,112,0,0" Width="269">
<Border BorderBrush="Silver" BorderThickness="5" Height="100" Width="200">
<TextBlock Height="69" Name="textBlock1" Text="TextBlock" />
</Border>
</ScrollViewer>


Code example for outside border:
外部边界的代码示例:
<Border BorderBrush="Silver" BorderThickness="5" Height="100" HorizontalAlignment="Left" Margin="167,104,0,0" Name="border1" VerticalAlignment="Top" Width="200">
<ScrollViewer Height="83" Name="sv" Width="184">
<TextBlock Name="textBlock1" Text="TextBlock TextBlockTextBlockTextBlock TextBlock TextBlock TextBlock TextBlock TextBlockTextBlockTextBlock TextBlock TextBlock TextBloc TextBlock TextBlockTextBlockTextBlock TextBlock TextBlock TextBloc TextBlock TextBlockTextBlockTextBlock TextBlock TextBlock TextBloc" TextWrapping="Wrap" />
</ScrollViewer>
</Border>



