summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-09-13 12:53:43 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:32:15 (GMT)
commit85216c8b988264332d168d66a80bad2543072f79 (patch)
tree6195a81bf0dda3b17619fd055e0fe5714729990d /Xamarin.Forms.Core
parentb3a790fb0a7182c9bfe7a18196f8a10916903faf (diff)
downloadxamarin-forms-85216c8b988264332d168d66a80bad2543072f79.zip
xamarin-forms-85216c8b988264332d168d66a80bad2543072f79.tar.gz
xamarin-forms-85216c8b988264332d168d66a80bad2543072f79.tar.bz2
[C] MergedRD: new tests and minor fixes
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/ResourceDictionary.cs70
1 files changed, 37 insertions, 33 deletions
diff --git a/Xamarin.Forms.Core/ResourceDictionary.cs b/Xamarin.Forms.Core/ResourceDictionary.cs
index c9d59f8..b3cb321 100644
--- a/Xamarin.Forms.Core/ResourceDictionary.cs
+++ b/Xamarin.Forms.Core/ResourceDictionary.cs
@@ -14,8 +14,9 @@ namespace Xamarin.Forms
{
static ConditionalWeakTable<Type, ResourceDictionary> s_instances = new ConditionalWeakTable<Type, ResourceDictionary>();
readonly Dictionary<string, object> _innerDictionary = new Dictionary<string, object>();
-
+ ResourceDictionary _mergedInstance;
Type _mergedWith;
+
[TypeConverter (typeof(TypeTypeConverter))]
public Type MergedWith {
get { return _mergedWith; }
@@ -35,57 +36,60 @@ namespace Xamarin.Forms
}
}
- ResourceDictionary _mergedInstance;
- public ICollection<ResourceDictionary> MergedDictionaries { get; private set; }
-
- public ResourceDictionary()
- {
- var collection = new ObservableCollection<ResourceDictionary>();
- collection.CollectionChanged += MergedDictionaries_CollectionChanged;
- MergedDictionaries = collection;
+ ICollection<ResourceDictionary> _mergedDictionaries;
+ public ICollection<ResourceDictionary> MergedDictionaries {
+ get {
+ if (_mergedDictionaries == null) {
+ var col = new ObservableCollection<ResourceDictionary>();
+ col.CollectionChanged += MergedDictionaries_CollectionChanged;
+ _mergedDictionaries = col;
+ }
+ return _mergedDictionaries;
+ }
}
+ IList<ResourceDictionary> _collectionTrack;
+
void MergedDictionaries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- // Movement of items doesn't affect monitoring of events
+ // Move() isn't exposed by ICollection
if (e.Action == NotifyCollectionChangedAction.Move)
return;
+ _collectionTrack = _collectionTrack ?? new List<ResourceDictionary>();
+ // Collection has been cleared
+ if (e.Action == NotifyCollectionChangedAction.Reset) {
+ foreach (var dictionary in _collectionTrack)
+ dictionary.ValuesChanged -= Item_ValuesChanged;
+
+ _collectionTrack.Clear();
+ return;
+ }
+
// New Items
- var newItems = e.NewItems?.Cast<ResourceDictionary>();
- if (newItems != null)
+ if (e.NewItems != null)
{
- foreach (var item in newItems)
+ foreach (var item in e.NewItems)
{
- _collectionTrack.Add(item);
- item.ValuesChanged += Item_ValuesChanged;
+ var rd = (ResourceDictionary)item;
+ _collectionTrack.Add(rd);
+ rd.ValuesChanged += Item_ValuesChanged;
+ OnValuesChanged(rd.ToArray());
}
-
- if (newItems.Count() > 0)
- OnValuesChanged(newItems.SelectMany(x => x).ToArray());
}
// Old Items
- var oldItems = e.OldItems?.Cast<ResourceDictionary>();
- if (oldItems != null)
- foreach (var item in oldItems)
+ if (e.OldItems != null)
+ {
+ foreach (var item in e.OldItems)
{
- item.ValuesChanged -= Item_ValuesChanged;
- _collectionTrack.Remove(item);
+ var rd = (ResourceDictionary)item;
+ rd.ValuesChanged -= Item_ValuesChanged;
+ _collectionTrack.Remove(rd);
}
-
- // Collection has been cleared
- if (e.Action == NotifyCollectionChangedAction.Reset)
- {
- foreach (var dictionary in _collectionTrack)
- dictionary.ValuesChanged -= Item_ValuesChanged;
-
- _collectionTrack.Clear();
}
}
- IList<ResourceDictionary> _collectionTrack = new List<ResourceDictionary>();
-
void Item_ValuesChanged(object sender, ResourcesChangedEventArgs e)
{
OnValuesChanged(e.Values.ToArray());