VisualState 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示控制項處於特定狀態時的視覺外觀。
public ref class VisualState : System::Windows::DependencyObject
[System.Windows.Markup.ContentProperty("Storyboard")]
[System.Windows.Markup.RuntimeNameProperty("Name")]
public class VisualState : System.Windows.DependencyObject
[<System.Windows.Markup.ContentProperty("Storyboard")>]
[<System.Windows.Markup.RuntimeNameProperty("Name")>]
type VisualState = class
inherit DependencyObject
Public Class VisualState
Inherits DependencyObject
- 繼承
- 屬性
範例
下列範例會在 VisualStateGroup 的 ButtonCommonStates
中ControlTemplate建立 ,並針對狀態 、Normal
、 Pressed
和 MouseOver
新增 VisualState 物件。 Button也會定義稱為 Disabled
的狀態,該狀態位於 CommonStates
VisualStateGroup中,但範例會省略它以求簡潔。 如需整個範例,請參閱 建立ControlTemplate來自定義現有控件的外觀。
<!--Define the states and transitions for the common states.
The states in the VisualStateGroup are mutually exclusive to
each other.-->
<VisualStateGroup x:Name="CommonStates">
<!--The Normal state is the state the button is in
when it is not in another state from this VisualStateGroup.-->
<VisualState x:Name="Normal" />
<!--Change the SolidColorBrush, BorderBrush, to red when the
mouse is over the button.-->
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BorderBrush"
Storyboard.TargetProperty="Color"
To="Red" />
</Storyboard>
</VisualState>
<!--Change the SolidColorBrush, BorderBrush, to Transparent when the
button is pressed.-->
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Storyboard.TargetName="BorderBrush"
Storyboard.TargetProperty="Color"
To="Transparent"/>
</Storyboard>
</VisualState>
<!--The Disabled state is omitted for brevity.-->
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
備註
VisualState指定控制件處於特定狀態時的外觀。 例如,按下 時 Button ,其框線可能會與一般色彩不同。 類別 VisualState 具有 Storyboard 可變更控件外觀的屬性。 當控件進入 屬性所 VisualState.Name 指定的狀態時,就會 Storyboard 開始。 當控件結束狀態時,會 Storyboard 停止。
屬性 VisualStateGroup.States 包含 VisualState 物件。 VisualStateGroup 物件會新增至 VisualStateManager.VisualStateGroups 附加屬性,其定義於 上的 FrameworkElement。 您可以將物件新增 VisualState 至任何 FrameworkElement,但它們通常用於 ControlTemplate 的 Control。 如需如何為現有控件建立 ControlTemplate 和 VisualState 物件的資訊,請參閱 建立ControlTemplate自定義現有控件的外觀。 如需在外部ControlTemplate使用 VisualState 物件的範例,請參閱 類別VisualStateManager。
建構函式
VisualState() |
初始化 VisualState 類別的新執行個體。 |
屬性
DependencyObjectType |
DependencyObjectType取得包裝這個實體之 CLR 型別的 。 (繼承來源 DependencyObject) |
Dispatcher |
取得與這個 Dispatcher 關聯的 DispatcherObject。 (繼承來源 DispatcherObject) |
IsSealed |
取得值,這個值表示此執行個體目前是否已密封 (唯讀)。 (繼承來源 DependencyObject) |
Name |
取得或設定 VisualState 的名稱。 |
Storyboard |
取得或設定 Storyboard,可定義控制項處於 VisualState 所表示之狀態時的外觀。 |
方法
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應