Default theme for WPF?

Asked 2 years ago, Updated 2 years ago, 92 views

I learned that WPF has a theme (theme here refers to Aero.NormalColor.xaml and so on, like a link).These themes are probably published in Github.
Regarding the topic, the reference article is old, so the situation may be different now, but I have a question.

Q1.What is the default theme for WPF?(What's on the link?)Or something else?Isn't it open source?)
Q2.Is it possible to find out which themes are currently applied by mechanical means for any WPF application?(For example, I would be happy if I could get the theme (.xaml file) used from .exe or .dll.Can I use dnSpy??)

The environment should be Windows 10, .NET Core 3.0, but you can add additional assumptions to answer.

Thank you for your cooperation.

c# .net wpf

2022-09-30 14:08

1 Answers

I have found a way to achieve it, so I will report it as an answer.

A1.As a result of A2, the conclusion was Aero2.NormalColor.xaml in this environment.
A2.Tried several methods

<Application.Resources>
  <ResourceDictionarySource="/PresentationFramework.<ThemeAssembly>component/themes/<ThemeFile>.xaml"/>
</Application.Resources>
    This method is invoked when loading DLLs, such as
  • Assembly.Load.
  • As a result of recording calls to this method, PresentationFramework.Aero2.dll was loaded in this environment and no other themed DLLs were loaded.
  • Based on the call stack of calls for this method, it appears that the DLL will eventually be selected based on the value returned by WinAPI GetCurrentThemeName (cf.UxThemeWrapper.GetThemeNameAndColor).
  • This method is invoked internally when loading an XAML file.
  • In the settings argument of this method, LocalAssembly can retrieve information about the DLL that contains the XAML resource, the XAML file that you are trying to load with the BaseUri property.
  • However, when loading the critical theme file (Aero2.NormalColor.xaml, LocalAssembly was PresentationFramework.Aero2, but BaseUri was null.This is probably because you are trying to load directly from Stream that corresponds to resources, not from Uri.
  • It may be used to investigate third-party libraries where documents are not yet developed.
  • The method called when retrieving resources (.xaml, .baml, etc.) from the DLL.Called inside the public method.
  • The
  • argument name appears to be able to retrieve information about the corresponding DLL from the resource name, instance MainAssembly property.
  • name found themes/aero2.normalcolor.baml.

These studies only show the DLLs and XAMLs loaded, and I'm not sure how they are applied in the actual WPF Tree, but I've accomplished my original goal, so I've stopped.

As a technical interest, I would like to continue to seek answers on how to conduct the above research in a reflective manner (i.e., in code).
If anyone has any knowledge, please let me know.


2022-09-30 14:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.