ResourceDictionary ResourceDictionary ResourceDictionary ResourceDictionary Class

定義

提供雜湊表/字典實作,其中包含元件及 WPF 應用程式之其他項目所使用的 WPF 資源。Provides a hash table / dictionary implementation that contains WPF resources used by components and other elements of a WPF application.

public ref class ResourceDictionary : System::Collections::IDictionary, System::ComponentModel::ISupportInitialize, System::Windows::Markup::INameScope, System::Windows::Markup::IUriContext
[System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)]
[System.Windows.Markup.Ambient]
[System.Windows.Markup.UsableDuringInitialization(true)]
public class ResourceDictionary : System.Collections.IDictionary, System.ComponentModel.ISupportInitialize, System.Windows.Markup.INameScope, System.Windows.Markup.IUriContext
type ResourceDictionary = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface ISupportInitialize
    interface IUriContext
    interface INameScope
Public Class ResourceDictionary
Implements IDictionary, INameScope, ISupportInitialize, IUriContext
繼承
ResourceDictionaryResourceDictionaryResourceDictionaryResourceDictionary
衍生
屬性
實作

備註

載入器載入XAMLXAML應用ResourceDictionary程式程式碼時,不會立即處理中的專案。The items in a ResourceDictionary are not immediately processed when application code is loaded by a XAMLXAML loader. 相反地, ResourceDictionary會以物件的形式保存,而且個別值只會在特別要求時處理。Instead, the ResourceDictionary persists as an object, and the individual values are processed only when they are specifically requested.

類別並非衍生自DictionaryBaseResourceDictionaryThe ResourceDictionary class is not derived from DictionaryBase. 相反地, ResourceDictionary IDictionary類別會執行Hashtable ,但會依賴內部。Instead, the ResourceDictionary class implements IDictionary but relies on a Hashtable internally.

Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML)ResourceDictionary ,類別通常是隱含的集合專案,這是在屬性專案語法中Resources提供的數個屬性的物件元素值。In Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML), the ResourceDictionary class is typically an implicit collection element that is the object element value of several Resources properties, when given in property element syntax. 如需中XAMLXAML隱含集合的詳細資訊,請參閱XAML 語法詳細資料For details on implicit collections in XAMLXAML, see XAML Syntax In Detail. 當您想要指定合併的字典時,就會發生例外狀況。如需詳細資訊,請參閱合併的資源字典An exception is when you want to specify a merged dictionary; for details, see Merged Resource Dictionaries.

另一個XAMLXAML可能的使用方式是將資源字典宣告為XAMLXAML獨立的檔案,並在執行時間載入Load它,或將它包含在(完全信任)專案中做為資源或鬆散檔案。Another possible XAMLXAML usage is to declare a resource dictionary as a discrete XAMLXAML file, and either load it at run time with Load or include it in a (full-trust) project as a resource or loose file. 在此情況下ResourceDictionary ,可以宣告為物件元素,做為的根項目。 XAMLXAMLIn this case, ResourceDictionary can be declared as an object element, serving as the root element of the XAMLXAML. 如果您打算使用它做為根項目,則必須WPFWPF將適當的x: XML 命名空間(命名空間ResourceDictionary的預設值,通常是XAMLXAML命名空間)對應到元素。You must map the appropriate XML namespace values (default for the WPFWPF namespace and typically x: for the XAMLXAML namespace) onto the ResourceDictionary element if you plan to use it as the root element. 然後,您可以加入定義資源的子項目,每個專案都有一個x:Key值。Then you can add child elements that define the resources, each with an x:Key value.

XAML 隱含集合用法XAML Implicit Collection Usage

<object>  
  <object.resourcesProperty>  
    oneOrMoreResources  
  </object.resourcesProperty>  
</object>  

XAML 值XAML Values

resourcesPropertyresourcesProperty
屬性,指定屬性專案,其中該屬性的數值型別為ResourceDictionaryA property specifying a property element, where the value type of that property is ResourceDictionary. 一般而言, Resources這是Application在應用程式FrameworkElement資源FrameworkContentElement案例中的或的屬性。Typically, this is the Resources property of FrameworkElement or FrameworkContentElement, or of Application in an application resources case.

oneOrMoreResourcesoneOrMoreResources
一或多個指定為物件元素的資源。One or more resources specified as object elements. 您指定的每個資源都必須指派x:Key指示詞。Each resource that you specify must have an x:Key Directive assigned.

建構函式

ResourceDictionary() ResourceDictionary() ResourceDictionary() ResourceDictionary()

初始化 ResourceDictionary 類別的新執行個體。Initializes a new instance of the ResourceDictionary class.

屬性

Count Count Count Count

取得基本 ResourceDictionary 中的項目數。Gets the number of entries in the base ResourceDictionary.

DeferrableContent DeferrableContent DeferrableContent DeferrableContent

取得或設定這個資源字典的可延遲內容。Gets or sets the deferrable content for this resource dictionary.

InvalidatesImplicitDataTemplateResources InvalidatesImplicitDataTemplateResources InvalidatesImplicitDataTemplateResources InvalidatesImplicitDataTemplateResources

取得或設定值,指出是否因 ResourceDictionary 物件讓 ContentPresenter 物件重新評估其選擇範本而引發失效。Gets or sets a value that indicates whether the invalidations fired by the ResourceDictionary object cause ContentPresenter objects to reevaluate their choice of template. 當隱含的資料範本資源變更時,就會造成失效。The invalidations happen when an implicit data template resource changes.

IsFixedSize IsFixedSize IsFixedSize IsFixedSize

取得這個 ResourceDictionary 是否為固定大小。Gets whether this ResourceDictionary is fixed-size.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得這個 ResourceDictionary 是否為唯讀。Gets whether this ResourceDictionary is read-only.

Item[Object] Item[Object] Item[Object] Item[Object]

取得或設定與指定索引鍵相關聯的值。Gets or sets the value associated with the given key.

Keys Keys Keys Keys

取得這個 ResourceDictionary 中包含的所有索引鍵的集合。Gets a collection of all keys contained in this ResourceDictionary.

MergedDictionaries MergedDictionaries MergedDictionaries MergedDictionaries

取得 ResourceDictionary 字典的集合,這些字典在合併字典中組成了各種資源字典。Gets a collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

Source Source Source Source

取得或設定要從其中載入資源的統一資源識別項 (URI)uniform resource identifier (URI)Gets or sets the 統一資源識別項 (URI)uniform resource identifier (URI) to load resources from.

Values Values Values Values

取得與這個 ResourceDictionary 中包含之索引鍵相關聯的所有值的集合。Gets a collection of all values associated with keys contained in this ResourceDictionary.

方法

Add(Object, Object) Add(Object, Object) Add(Object, Object) Add(Object, Object)

將資源依索引鍵加入這個 ResourceDictionaryAdds a resource by key to this ResourceDictionary.

BeginInit() BeginInit() BeginInit() BeginInit()

開始這個 ResourceDictionary 的初始化階段。Begins the initialization phase for this ResourceDictionary.

Clear() Clear() Clear() Clear()

清除基本 ResourceDictionary 中的所有索引鍵及值。Clears all keys (and values) in the base ResourceDictionary. 這不會清除任何合併的字典項目。This does not clear any merged dictionary items.

Contains(Object) Contains(Object) Contains(Object) Contains(Object)

判斷 ResourceDictionary 是否包含具有指定之索引鍵的項目。Determines whether the ResourceDictionary contains an element with the specified key.

CopyTo(DictionaryEntry[], Int32) CopyTo(DictionaryEntry[], Int32) CopyTo(DictionaryEntry[], Int32) CopyTo(DictionaryEntry[], Int32)

ResourceDictionary 元素複製到指定索引的一維 DictionaryEntryCopies the ResourceDictionary elements to a one-dimensional DictionaryEntry at the specified index.

EndInit() EndInit() EndInit() EndInit()

結束初始化階段,然後使前一樹狀結構失效,以便可說明初始化階段期間對索引鍵進行的所有變更。Ends the initialization phase, and invalidates the previous tree such that all changes made to keys during the initialization phase can be accounted for.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindName(String) FindName(String) FindName(String) FindName(String)

此「字典」實作不支援。Not supported by this Dictionary implementation.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回可用於在 IDictionaryEnumerator 中逐一查看的 ResourceDictionaryReturns an IDictionaryEnumerator that can be used to iterate through the ResourceDictionary.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnGettingValue(Object, Object, Boolean) OnGettingValue(Object, Object, Boolean) OnGettingValue(Object, Object, Boolean) OnGettingValue(Object, Object, Boolean)

ResourceDictionary 收到資源的要求時發生。Occurs when the ResourceDictionary receives a request for a resource.

RegisterName(String, Object) RegisterName(String, Object) RegisterName(String, Object) RegisterName(String, Object)

此「字典」實作不支援。Not supported by this Dictionary implementation.

Remove(Object) Remove(Object) Remove(Object) Remove(Object)

將具有指定索引鍵的項目從基本字典中移除。Removes the entry with the specified key from the base dictionary.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
UnregisterName(String) UnregisterName(String) UnregisterName(String) UnregisterName(String)

此「字典」實作不支援。Not supported by this Dictionary implementation.

明確介面實作

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

如需這個成員的說明,請參閱 CopyTo(Array, Int32)For a description of this member, see CopyTo(Array, Int32).

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

如需這個成員的說明,請參閱 IsSynchronizedFor a description of this member, see IsSynchronized.

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

如需這個成員的說明,請參閱 SyncRootFor a description of this member, see SyncRoot.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()For a description of this member, see GetEnumerator().

IUriContext.BaseUri IUriContext.BaseUri IUriContext.BaseUri IUriContext.BaseUri

如需這個成員的說明,請參閱 BaseUriFor a description of this member, see BaseUri.

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱