2016-04-25 59 views

回答

2

According to MSDN

  • 殘疾人

    一個滾動條,甚至沒有出現在視口中無法顯示所有的內容。內容的維度設置爲ScrollViewer父級的相應維度。對於水平滾動條,內容的寬度設置爲ScrollViewer的ViewportWidth。對於垂直ScrollBar,內容的高度設置爲ScrollViewer的ViewportHeight。

  • 隱藏

    一個滾動條,甚至沒有出現在視口中無法顯示所有的內容。 ScrollViewer的尺寸不適用於內容。

你有它。當你禁用一個水平或垂直滾動​​條,你告訴它不要在該維度上顯示一個滾動條,在該維度中的行爲類似於BorderGrid:內容大小爲容器 - 如果內容願意大小。在下面的例子中,我使用了帶有'TextWrapping ='Wrap'的TextBlock。如果我使用了固定大小的內容,那麼兩個ScrollViewer之間就不會有明顯的差異。固定大小的內容可能是以下幾點:

<Ellipse Width="300" Height="150" Fill="DodgerBlue" /> 

當你只是隱藏一個滾動條,你就是這個滾動條不可見,但ScrollViewer仍將允許它的內容比本身寬/高。如果內容想要,內容仍然可以比ScrollViewer更寬/更高。

下面是一個簡單的例子,說明了區別:

<Grid 
    > 
    <Grid.Resources> 
     <Style TargetType="TextBlock"> 
      <Setter Property="TextWrapping" Value="Wrap" /> 
      <Setter Property="Text"> 
       <Setter.Value> 
        Lorem Ipsum is simply dummy text of the printing and 
        typesetting industry. Lorem Ipsum has been the industry's 
        standard dummy text ever since the 1500s, when an unknown 
        printer took a galley of type and scrambled it to make a 
        type specimen book. 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Grid.Resources> 

    <StackPanel Orientation="Horizontal"> 
     <ScrollViewer 
      Width="200" 
      Height="100" 
      Margin="4" 
      HorizontalScrollBarVisibility="Disabled"> 
      <TextBlock /> 
     </ScrollViewer> 
     <ScrollViewer 
      Width="200" 
      Height="100" 
      Margin="4" 
      HorizontalScrollBarVisibility="Hidden"> 
      <TextBlock /> 
     </ScrollViewer> 
    </StackPanel> 
</Grid> 

OUTPUT

Output

而這裏的與該固定大小的橢圓形的文本取代的輸出:

enter image description here

+0

你能舉個例子嗎? –

+0

@KyloRen新增示例 –

+0

謝謝...這就是完美的例子... :) –