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
衍生
屬性
實作

備註

中的項目ResourceDictionary不會立即處理當應用程式程式碼會載入XAMLXAML載入器。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.

ResourceDictionary類別不衍生自DictionaryBaseThe 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. 您必須將適當的 XML 命名空間值對應 (項目的預設值WPFWPF命名空間和通常x:forXAMLXAML命名空間) 拖曳至ResourceDictionary項目,如果您打算使用的根項目。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的屬性FrameworkElement或是FrameworkContentElement,或Application在應用程式資源的情況下。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 的淺層複製。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.

Extension Methods

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)

將轉換IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱