public bool Contains(object key) { if (key == null) { throw new ArgumentNullException("key"); } if (!(key is string || key is Type)) { throw new ArgumentException("Key must be a string or Type"); } if (managedDict != null && managedDict.ContainsKey(key)) { return(true); } PresentationFrameworkCollection <ResourceDictionary> col = MergedDictionaries; for (int i = col.Count - 1; i >= 0; i--) { ResourceDictionary rd = col[i]; if (rd.Contains(key)) { return(true); } } return(false); }
internal override void AddStrongRef(IntPtr id, object value) { if (id == ResourceDictionary.MergedDictionariesProperty.Native) { mergedDictionaries = (PresentationFrameworkCollection <ResourceDictionary>)value; } else { base.AddStrongRef(id, value); } }
internal override void ClearStrongRef(IntPtr id, object value) { if (id == ResourceDictionary.MergedDictionariesProperty.Native) { mergedDictionaries = null; } else { base.ClearStrongRef(id, value); } }
public object this[object key] { get { if (!(key is string || key is Type)) { throw new ArgumentException("Key must be a string or Type"); } // check our cache if (managedDict != null && managedDict.ContainsKey(key)) { return(managedDict[key]); } // now iterate over the merged dictionaries PresentationFrameworkCollection <ResourceDictionary> col = MergedDictionaries; for (int i = col.Count - 1; i >= 0; i--) { ResourceDictionary rd = col[i]; if (rd.Contains(key)) { return(rd[key]); } } return(null); } set { // this setter only permits string // keys. since unmanaged needs to // access them we send it along to // unmanaged as well as update our // cache. var str_key = ToStringKey(key); using (var val = Value.FromObject(value, true)) { var v = val; if (NativeMethods.resource_dictionary_set(native, str_key, ref v)) { if (managedDict == null) { managedDict = new Dictionary <object, object> (); } managedDict.Add(str_key, value); } } } }