Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,10 @@ internal void AddOwner(DispatcherObject owner)
fe.ShouldLookupImplicitStyles = true;
}

// Owned dictionaries are never theme dictionaries; clear the flag the ctor may
// have inherited from SystemResources.IsSystemResourcesParsing. Propagates to merged dictionaries.
IsThemeDictionary = false;
Comment thread
amarinov-msft marked this conversation as resolved.

_ownerFEs.Add(fe);
}
else
Expand All @@ -1530,6 +1534,10 @@ internal void AddOwner(DispatcherObject owner)
fce.ShouldLookupImplicitStyles = true;
}

// Owned dictionaries are never theme dictionaries; clear the flag the ctor may
// have inherited from SystemResources.IsSystemResourcesParsing. Propagates to merged dictionaries.
IsThemeDictionary = false;

_ownerFCEs.Add(fce);
}
else
Expand Down Expand Up @@ -1557,6 +1565,10 @@ internal void AddOwner(DispatcherObject owner)
// An Application ResourceDictionary can be accessed across threads
CanBeAccessedAcrossThreads = true;

// Owned dictionaries are never theme dictionaries; clear the flag the ctor may
// have inherited from SystemResources.IsSystemResourcesParsing. Propagates to merged dictionaries.
IsThemeDictionary = false;

// Seal all the styles and templates in this app dictionary
SealValues();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
Expand Down Expand Up @@ -159,4 +160,19 @@ public void DynamicResource_ShouldRemainLastValue_WhenLocalResourceRemoved()
// The default foreground color of textBlock (as in aero2)
textBlock.Foreground.Should().BeSameAs(Brushes.Black);
}

[WpfFact]
public void AddOwner_ClearsInheritedIsThemeDictionaryFlag()
{
// Simulate a ResourceDictionary whose ctor inherited
// IsThemeDictionary from SystemResources.IsSystemResourcesParsing.
PropertyInfo isThemeDictionary = typeof(ResourceDictionary).GetProperty(
"IsThemeDictionary", BindingFlags.Instance | BindingFlags.NonPublic)!;
var rd = new ResourceDictionary();
isThemeDictionary.SetValue(rd, true);

_ = new Button { Resources = rd };

isThemeDictionary.GetValue(rd).Should().Be(false);
}
}