- XAML 教程
- XAML - 首頁
- XAML - 概述
- XAML - 環境設定
- 在 macOS 上編寫 XAML 應用程式
- XAML 與 C# 程式碼
- XAML 與 VB.NET
- XAML - 構建塊
- XAML - 控制元件
- XAML - 佈局
- XAML - 事件處理
- XAML - 資料繫結
- XAML - 標記擴充套件
- XAML - 依賴屬性
- XAML - 資源
- XAML - 模板
- XAML - 樣式
- XAML - 觸發器
- XAML - 除錯
- XAML - 自定義控制元件
- XAML 有用資源
- XAML - 快速指南
- XAML - 有用資源
- XAML - 討論
XAML - 進度條
ProgressBar 表示一個控制元件,用於指示操作的進度,其典型視覺外觀是一個條形,隨著進度的繼續,動畫填充區域。它可以透過以下兩種樣式之一顯示進度:
- 顯示重複圖案的條形,或
- 根據值填充的條形。
ProgressBar 類的繼承層次結構如下所示:
屬性
| 序號 | 屬性及描述 |
|---|---|
| 1 | IsIndeterminate 獲取或設定一個值,該值指示進度條是否使用重複模式報告通用進度,或者根據 Value 屬性報告進度。 |
| 2 | IsIndeterminateProperty 標識 IsIndeterminate 依賴屬性。 |
| 3 | ShowError 獲取或設定一個值,該值指示進度條是否應使用向用戶傳達錯誤狀態的視覺狀態。 |
| 4 | ShowErrorProperty 標識 ShowError 依賴屬性。 |
| 5 | ShowPaused 獲取或設定一個值,該值指示進度條是否應使用向用戶傳達暫停狀態的視覺狀態。 |
| 6 | ShowPausedProperty 標識 ShowPaused 依賴屬性。 |
| 7 | TemplateSettings 獲取一個物件,該物件提供計算出的值,這些值可以在定義 ProgressBar 控制元件的模板時作為 TemplateBinding 源進行引用。 |
事件
| 序號 | 事件及描述 |
|---|---|
| 1 | ManipulationCompleted 當對 UIElement 的操作完成時發生。(從 UIElement 繼承) |
| 2 | ManipulationDelta 當輸入裝置在操作過程中改變位置時發生。(從 UIElement 繼承) |
| 3 | ManipulationInertiaStarting 當輸入裝置在操作過程中與 UIElement 物件失去接觸並開始慣性時發生。(從 UIElement 繼承) |
| 4 | ManipulationStarted 當輸入裝置開始對 UIElement 進行操作時發生。(從 UIElement 繼承) |
| 5 | ManipulationStarting 當首次建立操作處理器時發生。(從 UIElement 繼承) |
| 6 | ValueChanged 當範圍值更改時發生。(從 RangeBase 繼承) |
方法
| 序號 | 方法及描述 |
|---|---|
| 1 | OnManipulationCompleted 在 ManipulationCompleted 事件發生之前呼叫。(從 Control 繼承) |
| 2 | OnManipulationDelta 在 ManipulationDelta 事件發生之前呼叫。(從 Control 繼承) |
| 3 | OnManipulationInertiaStarting 在 ManipulationInertiaStarting 事件發生之前呼叫。(從 Control 繼承) |
| 4 | OnManipulationStarted 在 ManipulationStarted 事件發生之前呼叫。(從 Control 繼承) |
| 5 | OnManipulationStarting 在 ManipulationStarting 事件發生之前呼叫。(從 Control 繼承) |
| 6 | OnMaximumChanged 當 Maximum 屬性更改時呼叫。(從 RangeBase 繼承) |
| 7 | OnMinimumChanged 當 Minimum 屬性更改時呼叫。(從 RangeBase 繼承) |
| 8 | OnValueChanged 觸發 ValueChanged 路由事件。(從 RangeBase 繼承) |
| 9 | SetBinding 使用提供的繫結物件將繫結附加到 FrameworkElement。(從 FrameworkElement 繼承) |
| 10 | SetValue 設定 DependencyObject 上依賴屬性的本地值。(從 DependencyObject 繼承) |
示例
以下示例演示如何使用 ProgressBar 控制元件。以下是建立並初始化兩個具有 **IsIndeterminate** 屬性的 ProgressBar 控制元件的 XAML 程式碼。
<Window x:Class = "ProgressBar.MainWindow"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "MainWindow" Height = "350" Width = "525">
<Grid>
<StackPanel x:Name = "LayoutRoot" >
<Border BorderThickness = "5" BorderBrush = "LightCoral">
<StackPanel Background = "LightBlue">
<TextBlock HorizontalAlignment = "Center" Margin = "10"
Text = "Value-Based Progress Bar" />
<ProgressBar x:Name = "pg1" Value = "100" Margin = "10" Maximum = "200"
Height = "15" IsIndeterminate = "False" />
</StackPanel>
</Border>
<Border BorderThickness = "5" BorderBrush = "LightCoral">
<StackPanel Background = "LightBlue">
<TextBlock HorizontalAlignment = "Center" Margin = "10" Text = "Indeterminate Progress Bar" />
<ProgressBar x:Name = "pg2" Margin = "10" Height = "15" IsIndeterminate = "True" />
</StackPanel>
</Border>
</StackPanel>
</Grid>
</Window>
編譯並執行上述程式碼後,將生成以下輸出:
建議您執行上述示例程式碼,並嘗試一些其他屬性和事件。