2012-09-16 42 views
0

我有WPF應用程序,在我的一個WPF窗體中有TextBlock。我將TextBlock放置在ScrollViewer中以提供滾動功能。我想TextBlock邊框,所以,我已經寫在XAML以下代碼。當TextBlock放置在ScrollViewer裏時在TextBlock上顯示邊框

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

使用scrollBar 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中時,如何顯示邊框?

+0

我解決了<邊框BorderBrush = 「黑」 了borderThickness = 「1」 保證金= 「230,32,12,147」> <的ScrollViewer>

回答

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

+0

不工作。邊框不顯示。 –

+0

您是否設置了「BorderBrush」顏色? – opewix

+0

是的,在設置BorderBrush =「Black」後不顯示邊框 –