Skip to content

Commit

Permalink
fix: uwp crash with WithImplicitStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Mar 14, 2022
1 parent 60e627d commit bc3b542
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/library/Uno.Cupertino/CupertinoResources.cs
Expand Up @@ -85,6 +85,7 @@ private void ExportImplicitStyles(bool value)
{
if (!value) return; // we don't support teardown

var implicitResources = new ResourceDictionary();
foreach (var info in GetResourceInfos())
{
foreach (var key in info.ImplicitStyles ?? Array.Empty<string>())
Expand All @@ -103,9 +104,14 @@ private void ExportImplicitStyles(bool value)
throw new InvalidOperationException($"Missing TargetType on style: key={key}");
}

this.Add(style.TargetType, style);
implicitResources.Add(style.TargetType, style);
}
}

// UWP don't allow for res-dict with Source set to contain resource directly:
// > Local values are not allowed in resource dictionary with Source set
// but, we can add them through merged-dict instead.
this.MergedDictionaries.Add(implicitResources);
}
}
}
8 changes: 7 additions & 1 deletion src/library/Uno.Material/MaterialResources.cs
Expand Up @@ -78,6 +78,7 @@ private void ExportImplicitStyles(bool value)
{
if (!value) return; // we don't support teardown

var implicitResources = new ResourceDictionary();
foreach (var key in GetImplicitStyles())
{
if (!this.TryGetValue(key, out var resource) || !(resource is Style style))
Expand All @@ -94,8 +95,13 @@ private void ExportImplicitStyles(bool value)
throw new InvalidOperationException($"Missing TargetType on style: key={key}");
}

this.Add(style.TargetType, style);
implicitResources.Add(style.TargetType, style);
}

// UWP don't allow for res-dict with Source set to contain resource directly:
// > Local values are not allowed in resource dictionary with Source set
// but, we can add them through merged-dict instead.
this.MergedDictionaries.Add(implicitResources);
}
}
}

0 comments on commit bc3b542

Please sign in to comment.