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

屬性值

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.

適用於

另請參閱