다음을 통해 공유


ResourceDictionary.Add Method (Object, Object)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Adds an item to the ResourceDictionary.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub Add ( _
    key As Object, _
    value As Object _
)
public void Add(
    Object key,
    Object value
)

Parameters

Implements

IDictionary.Add(Object, Object)

Exceptions

Exception Condition
NotSupportedException

Attempted to add nulla null reference (Nothing in Visual Basic) as a value.

ArgumentException

Attempted to add an item with a key that already exists in this ResourceDictionary.

-or-

Attempted to use a key that is not a string.

Remarks

ResourceDictionary supports dictionary APIs that support two signatures for the type of the key component, one that takes strings and one that takes Object. Most Silverlight scenarios should use strings as the resource key for resources in a ResourceDictionary. The Object as key signatures exist for compatibility and for interface conformance, but internally the dictionary is implemented such that only strings are accepted as keys. See "Keys and Resources" section of Resource Dictionaries.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.