ResourceDictionary 類別

定義

提供雜湊表/字典實作,其中包含元件及 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
[System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)]
public 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)>]
type ResourceDictionary = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface ISupportInitialize
    interface INameScope
    interface IUriContext
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)>]
type ResourceDictionary = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface INameScope
    interface ISupportInitialize
    interface IUriContext
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)>]
[<System.Windows.Markup.Ambient>]
[<System.Windows.Markup.UsableDuringInitialization(true)>]
type ResourceDictionary = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface ISupportInitialize
    interface IUriContext
    interface INameScope
Public Class ResourceDictionary
Implements IDictionary, INameScope, ISupportInitialize, IUriContext
繼承
ResourceDictionary
衍生
屬性
實作

備註

ResourceDictionaryXAML 載入器載入應用程式程式碼時,不會立即處理中的專案。The items in a ResourceDictionary are not immediately processed when application code is loaded by a XAML 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.

在可延伸應用程式標記語言 (XAML) 中,此 ResourceDictionary 類別通常是隱含的集合專案,也就是多個屬性的物件元素值 Resources (當提供屬性元素語法時)。In 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. 如需 XAML 中隱含集合的詳細資訊,請參閱 Xaml 語法詳細資料For details on implicit collections in XAML, see XAML Syntax In Detail. 例外狀況是當您想要指定合併的字典時,如需詳細資訊,請參閱 合併的資源字典An exception is when you want to specify a merged dictionary; for details, see Merged Resource Dictionaries.

另一個可能的 XAML 用法是將資源字典宣告為離散的 XAML 檔案,然後在執行時間載入它, Load 或將它包含在 (的完全信任) 專案中做為資源或鬆散式檔案。Another possible XAML usage is to declare a resource dictionary as a discrete XAML 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 可以宣告為物件元素,做為 XAML 的根項目。In this case, ResourceDictionary can be declared as an object element, serving as the root element of the XAML. 您必須將適當的 XML 命名空間值對應至 WPF 命名空間 (預設值,而且 x: ResourceDictionary 如果您打算使用它做為根項目,通常會將 XAML 命名空間) 至專案。You must map the appropriate XML namespace values (default for the WPF namespace and typically x: for the XAML 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
指定 property 專案的屬性,其中該屬性的值型別為 ResourceDictionaryA property specifying a property element, where the value type of that property is ResourceDictionary. 一般來說,這是 Resources FrameworkElementFrameworkContentElement 的屬性,或是 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 類別的新執行個體。Initializes a new instance of the ResourceDictionary class.

屬性

Count

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

DeferrableContent

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

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

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

IsReadOnly

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

Item[Object]

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

Keys

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

MergedDictionaries

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

Source

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

Values

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

方法

Add(Object, Object)

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

BeginInit()

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

Clear()

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

Contains(Object)

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

CopyTo(DictionaryEntry[], Int32)

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

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)

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

(繼承來源 Object)
FindName(String)

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

GetEnumerator()

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

GetHashCode()

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

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnGettingValue(Object, Object, Boolean)

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

RegisterName(String, Object)

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

Remove(Object)

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

ToString()

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

(繼承來源 Object)
UnregisterName(String)

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

明確介面實作

ICollection.CopyTo(Array, Int32)

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

ICollection.IsSynchronized

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

ICollection.SyncRoot

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

IEnumerable.GetEnumerator()

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

IUriContext.BaseUri

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

擴充方法

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱