ScrollBarVisibility 列舉

定義

為可捲動的內容指定 ScrollBar 的可視性。

public enum class ScrollBarVisibility
public enum ScrollBarVisibility
type ScrollBarVisibility = 
Public Enum ScrollBarVisibility
繼承
ScrollBarVisibility

欄位

Auto 1

當檢視區不能顯示所有內容,會顯示 ScrollBar,且 ScrollViewer 的維度會套用至內容。 如需水平的 ScrollBar,內容寬度會設定為 ViewportWidthScrollViewer。 如需垂直的 ScrollBar,內容高度會設定為 ViewportHeightScrollViewer

Disabled 0

即使檢視區不能顯示所有內容,也不會顯示 ScrollBar。 內容的維度會設為 ScrollViewer 父代的對應維度。 如需水平的 ScrollBar,內容寬度會設定為 ViewportWidthScrollViewer。 如需垂直的 ScrollBar,內容高度會設定為 ViewportHeightScrollViewer

Hidden 2

即使檢視區不能顯示所有內容,也不會顯示 ScrollBarScrollViewer 的維度不會套用至內容。

Visible 3

ScrollBar 永遠會出現。 ScrollViewer 的維度會套用至內容。 如需水平的 ScrollBar,內容寬度會設定為 ViewportWidthScrollViewer。 如需垂直的 ScrollBar,內容高度會設定為 ViewportHeightScrollViewer

範例

下列範例示範如何使用這個列舉的成員值來設定 HorizontalScrollBarVisibility 控制項的 ScrollViewer 屬性。


// Create the application's main window
mainWindow = gcnew System::Windows::Window();
mainWindow->Title = "ScrollViewer Sample";

// Define a ScrollViewer
myScrollViewer = gcnew ScrollViewer();
myScrollViewer->HorizontalScrollBarVisibility = ScrollBarVisibility::Auto;

// Add Layout control
myStackPanel = gcnew StackPanel();
myStackPanel->HorizontalAlignment = HorizontalAlignment::Left;
myStackPanel->VerticalAlignment = VerticalAlignment::Top;

TextBlock^ myTextBlock = gcnew TextBlock();
myTextBlock->TextWrapping = TextWrapping::Wrap;
myTextBlock->Margin = System::Windows::Thickness(0, 0, 0, 20);
myTextBlock->Text = "Scrolling is enabled when it is necessary. Resize the Window, making it larger and smaller.";

Rectangle^ myRectangle = gcnew 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();

// 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 ();

'Define a ScrollViewer.
Dim myScrollViewer As New ScrollViewer
myScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto

'Add Layout control.
Dim myStackPanel As New StackPanel
myStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left
myStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top

Dim myTextBlock As 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."

Dim myRectangle As 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
Me.Content = myScrollViewer
<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 維度套用至其封入的內容。

當您將 ViewportWidthViewportHeight 套用至 ScrollViewer 內容時,您可以設定內容的檢視區大小。

適用於

另請參閱