当TextBlock放在ScrollViewer中时,在TextBlock上显示边框

时间:2012-09-16 06:19:30

标签: c# wpf user-interface

我有WPF应用程序,在我的一个WPF表单中有TextBlock。我将TextBlock放在ScrollViewer中以提供滚动功能。我想在TextBlock上使用Border,所以我在XAML中编写了以下代码。

<ScrollViewer Margin="230,32,12,147">
    <Border BorderThickness="1" BorderBrush="Black">
          <TextBlock Name="textBlock1"></TextBlock>
      </Border>
 </ScrollViewer>

滚动条GUI显示如下。

enter image description here

向下滚动到TextBlock时显示底部边框。用户体验不适合这种设计。所以,我尝试使用下面的代码但边框没有显示。

<Border BorderThickness="1" BorderBrush="Black">
    <ScrollViewer Margin="230,32,12,147">
          <TextBlock Name="textBlock1"></TextBlock>
     </ScrollViewer>
 </Border>

当TextBlock放在ScrollViewer中时,如何显示边框?

1 个答案:

答案 0 :(得分:5)

在ScrollViewer控件中设置边框!

<ScrollViewer Margin="230,32,12,147" BorderThickness="5">
      <TextBlock Name="textBlock1"></TextBlock>
 </ScrollViewer>

在属性窗口中,展开Other组并设置BorderThickness

下一个代码效果很好:

<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>

enter image description here

外部边界的代码示例:

<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>

enter image description here