ScrollBarVisibility 枚举

定义

指定可滚动内容的 ScrollBar 的可见性。

C#
public enum ScrollBarVisibility
继承
ScrollBarVisibility

字段

名称 说明
Auto 1

当视区无法显示所有内容时,ScrollBar 会出现,并将 ScrollViewer 的维度应用于内容。 对于水平 ScrollBar,内容的宽度设置为 ViewportWidthScrollViewer。 对于垂直 ScrollBar,内容的高度设置为 ViewportHeightScrollViewer

Disabled 0

即使当视区无法显示所有内容时,ScrollBar 也不会出现。 将内容的维度设置为 ScrollViewer 父级的对应维度。 对于水平 ScrollBar,内容的宽度设置为 ViewportWidthScrollViewer。 对于垂直 ScrollBar,内容的高度设置为 ViewportHeightScrollViewer

Hidden 2

即使当视区无法显示所有内容时,ScrollBar 也不会出现。 未将 ScrollViewer 的维度应用于内容。

Visible 3

ScrollBar 始终出现。 将 ScrollViewer 的维度应用于内容。 对于水平 ScrollBar,内容的宽度设置为 ViewportWidthScrollViewer。 对于垂直 ScrollBar,内容的高度设置为 ViewportHeightScrollViewer

示例

以下示例演示如何使用此枚举的成员值来设置 HorizontalScrollBarVisibility 控件的 ScrollViewer 属性。

C#

// Create the application's main window
mainWindow = new Window ();
mainWindow.Title = "ScrollViewer Sample";

// Define a ScrollViewer
myScrollViewer = new ScrollViewer();
myScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

// Add Layout control
myStackPanel = new StackPanel();
myStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
myStackPanel.VerticalAlignment = VerticalAlignment.Top;

TextBlock myTextBlock = new TextBlock();
myTextBlock.TextWrapping = TextWrapping.Wrap;
myTextBlock.Margin = new Thickness(0, 0, 0, 20);
myTextBlock.Text = "Scrolling is enabled when it is necessary. Resize the Window, making it larger and smaller.";

Rectangle myRectangle = new Rectangle();
myRectangle.Fill = Brushes.Red;
myRectangle.Width = 500;
myRectangle.Height = 500;

// Add child elements to the parent StackPanel
myStackPanel.Children.Add(myTextBlock);
myStackPanel.Children.Add(myRectangle);
            
// Add the StackPanel as the lone Child of the Border
myScrollViewer.Content = myStackPanel;

// Add the Border as the Content of the Parent Window Object
mainWindow.Content = myScrollViewer;
mainWindow.Show ();
XAML
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      WindowTitle="ScrollViewer Sample">
  <ScrollViewer HorizontalScrollBarVisibility="Auto">
    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
      <TextBlock TextWrapping="Wrap" Margin="0,0,0,20">Scrolling is enabled when it is necessary. 
      Resize the window, making it larger and smaller.</TextBlock>
      <Rectangle Fill="Red" Width="500" Height="500"></Rectangle>
    </StackPanel>
  </ScrollViewer>
</Page>

注解

使用此枚举可设置 HorizontalScrollBarVisibility 控件的 ScrollViewerVerticalScrollBarVisibility 属性值。

此枚举的成员值指定 ScrollBar 给定方向的可见性。 这些成员值还指定是否将相应的 ScrollViewer 维度应用于其封闭内容。

将 或 ViewportHeight 应用于ViewportWidthScrollViewer内容时,可以设置内容的视区大小。

适用于

产品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅