FrameworkElement.Triggers 屬性

定義

取得直接在這個項目或子項目中建立的觸發程序集合。Gets the collection of triggers established directly on this element, or in child elements.

public:
 property System::Windows::TriggerCollection ^ Triggers { System::Windows::TriggerCollection ^ get(); };
public System.Windows.TriggerCollection Triggers { get; }
member this.Triggers : System.Windows.TriggerCollection
Public ReadOnly Property Triggers As TriggerCollection

屬性值

TriggerCollection

Trigger 物件的強類型集合。A strongly typed collection of Trigger objects.

備註

注意

這個屬性只能 Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML) 透過所顯示的集合語法來設定,或藉由存取集合物件並使用其各種方法(例如 Add)來設定。This property can only be set in Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML) through the collection syntax shown, or by accessing the collection object and using its various methods such as Add. 用來存取集合物件本身的屬性是唯讀的,而集合本身為讀寫。The property to access the collection object itself is read-only, the collection itself is read-write. 屬性只存在於根項目;嘗試在其他地方尋找或設定,將會擲回例外狀況。The property only exists on root elements; attempting to find it or set it elsewhere will cause an exception to be thrown.

這個屬性不會讓您檢查存在於此專案使用之樣式的觸發程式。This property does not enable you to examine triggers that exist as part of styles in use on this element. 它只會報告在標記或程式碼中要加入至集合的觸發程式集合。It only reports the collection of triggers that are literally added to the collection, either in markup or code. 依預設,專案不會有這類元素 (透過實例) 的範本;更常見的情況是,來自控制群組合的觸發程式是以樣式建立的。Elements do not typically have such elements existing by default (through a template for instance); it is more common for triggers that come from control compositing to be established in styles instead.

根據行為 (以及嘗試建立專案的宣告 Triggers 集合) 的效果,觸發條件和觸發程式效果可能會在此專案上,或可能在邏輯樹狀結構中的子項目上。In terms of behavior (and trying to establish which effect came from which element's declared Triggers collection), both the triggering condition and the trigger effect might be on this element, or might be on its child elements in the logical tree. 請注意,如果您使用的存留期事件(例如) Loaded 取得此集合,子專案的觸發程式可能尚未完全載入,而且集合會比在執行時間中真正的還小。Note that if you use lifetime events such as Loaded to get this collection, the child element's triggers might not yet be fully loaded, and the collection will be smaller than it would truly be at run time.

請注意,在元素上建立的觸發程式集合只支援 EventTrigger ,而不支援屬性觸發程式 (Trigger) 。Note that the collection of triggers established on an element only supports EventTrigger, not property triggers (Trigger). 如果您需要屬性觸發程式,則必須將這些專案放在樣式或範本內,然後直接透過屬性將該樣式或範本指派給專案 Style ,或間接透過隱含樣式參考。If you require property triggers, you must place these within a style or template and then assign that style or template to the element either directly through the Style property, or indirectly through an implicit style reference.

XAML 屬性項目用法XAML Property Element Usage

<object>  
  <object.Triggers>  
    oneOrMoreTriggers  
  </object.Triggers>  
</object>  

XAML 值XAML Values

oneOrMoreTriggersoneOrMoreTriggers
一或多個已定義 EventTrigger 的元素。One or more defined EventTrigger elements. 每個這類觸發程式都應該包含有效的分鏡腳本動作和參考。Each such trigger is expected to contain valid storyboard actions and references. 請注意,這個集合只能在頁面的根項目上建立。Note that this collection can only be established on the root element of a page. 如需詳細資訊,請參閱分鏡腳本概觀For more information, see Storyboards Overview.

適用於

另請參閱