Class ResourceDictionary
- Namespace
- Icy.UI
- Assembly
- IcyUI.dll
A string-keyed collection of named resources (Styles, Timelines, brushes, or any other value), optionally composed from other dictionaries via MergedDictionaries.
public class ResourceDictionary : IDictionary<string, object?>, ICollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IEnumerable
- Inheritance
-
ResourceDictionary
- Implements
- Inherited Members
- Extension Methods
Remarks
Every UIElement carries its own via Resources - lookup
({StaticResource}, see StaticResourceExtension) resolves once, at
load time, by walking outward from the innermost element currently under construction (the loader's
construction-time element stack, not Parent/LogicalParent -
see StaticResourceExtension's own remarks for why) to the document root,
checking each element's own Resources in turn before moving outward.
Within a single dictionary, a direct entry always shadows a same-key entry from MergedDictionaries; among merged dictionaries themselves, a later one shadows an earlier one on collision - both are intentional (theme layering), not errors.
Properties
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- bool
true if the ICollection<T> is read-only; otherwise, false.
this[string]
Gets or sets the element with the specified key.
public object? this[string key] { get; set; }
Parameters
keystringThe key of the element to get or set.
Property Value
- object
The element with the specified key.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
public ICollection<string> Keys { get; }
Property Value
- ICollection<string>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
MergedDictionaries
Gets the other dictionaries this one is composed from, checked in order (a later one shadows an earlier one) after this dictionary's own direct entries.
public IList<ResourceDictionary> MergedDictionaries { get; }
Property Value
Remarks
Only recognized in markup as a property element on a document's own root - a standalone
<ResourceDictionary> document loaded via LoadObject(string, string?) can
have a nested <ResourceDictionary.MergedDictionaries>, but nesting it under another
element's own dictionary-valued property (e.g. inside <Panel.Resources>) does not work today:
every child there is routed straight into keyed-entry population with no check for a nested property
element first. To merge into a Resources dictionary, add the loaded dictionary
directly in code instead: element.Resources.MergedDictionaries.Add(loadedDictionary) (there is no
setter for Resources itself - only MergedDictionaries's own
Add is available).
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
public ICollection<object?> Values { get; }
Property Value
- ICollection<object>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(KeyValuePair<string, object?>)
Adds an item to the ICollection<T>.
public void Add(KeyValuePair<string, object?> item)
Parameters
itemKeyValuePair<string, object>The object to add to the ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Add(string, object?)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(string key, object? value)
Parameters
keystringThe object to use as the key of the element to add.
valueobjectThe object to use as the value of the element to add.
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
An element with the same key already exists in the IDictionary<TKey, TValue>.
- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Contains(KeyValuePair<string, object?>)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(KeyValuePair<string, object?> item)
Parameters
itemKeyValuePair<string, object>The object to locate in the ICollection<T>.
Returns
- bool
true if
itemis found in the ICollection<T>; otherwise, false.
ContainsKey(string)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
CopyTo(KeyValuePair<string, object?>[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<string, object>[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
arrayIndexis less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndexto the end of the destinationarray.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, object>>
An enumerator that can be used to iterate through the collection.
GetImplicitStyleKey(Type)
Gets the reserved resource key an implicit Style targeting targetType
registers under.
public static string GetImplicitStyleKey(Type targetType)
Parameters
targetTypeTypeThe exact type the implicit style targets.
Returns
- string
The reserved key.
Remove(KeyValuePair<string, object?>)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(KeyValuePair<string, object?> item)
Parameters
itemKeyValuePair<string, object>The object to remove from the ICollection<T>.
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis not found in the original ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Remove(string)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
public bool Remove(string key)
Parameters
keystringThe key of the element to remove.
Returns
- bool
true if the element is successfully removed; otherwise, false. This method also returns false if
keywas not found in the original IDictionary<TKey, TValue>.
Exceptions
- ArgumentNullException
keyis null.- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
TryGetValue(string, out object?)
Looks up key in this dictionary's own entries, then in MergedDictionaries
(in reverse order, so a later merged dictionary wins).
public bool TryGetValue(string key, out object? value)