Access the contents of packed resource dictionary in WPF - wpf

How can I access and view the contents of a resource from a third-party library in WPF?
<ResourceDictionary Source="pack://application:,,,/XXX;component/Styles/Components.xaml" />

XAML is compiled into BAML so if you have a compiled third-party assembly, you'll need a decompiler that can decompile BAML to XAML. An example of such a decompiler is dotPeek.
If you download it (it's free of charge) and open the XXX assembly in it, you should be able to see the XAML markup of Styles/Components.xaml if you look for components.baml in the tree view in the assemmbly explorer.
Please refer to JetBrain's web site for more information about how to use dotPeek: https://www.jetbrains.com/decompiler/features/

Related

Embed BAML in assembly without WPF

I would like to embed compiled XAML into an assembly as BAML2006.
If the Embedded Resource MSBuild action is selected, the XAML file gets embedded into the assembly as a text resource that can be read like any other loose XAML resource. However, loose XAML has some serious limitations when it comes to referenced namespaces, most cripplingly, any namespace referred to by its [XmlnsDefinitionAttribute] must be loaded into the AppDomain before the loose XAML is parsed. In contrast, embedded BAML does not suffer from this, as the assembly containing the namespace is added to the list of referenced assemblies and is loaded by the AppDomain automatically before any code starts running.
If the Page MSBuild task is selected, XAML gets "compiled" into BAML2006 and is embedded to the .resources.g of the containing assembly. However, compilation will fail if the WindowsBase, PresentationCode and PresentationFramework assemblies are not referenced. As I am working on a project which uses XAML but not WPF (we load object graphs with XamlObjectWriter and custom markup extensions, but reuse the Visual Studio some of XAML editor infrastructure for IntelliSense support), I would like to avoid depending on these libraries.
Is there any way to make MSBuild embed BAML and add required assembly references without depending on WPF?
I guess Workflow Foundation uses a similar approach, but I haven't been able to find any information.

Using ildasm to detect markup differences between WPF assemblies

I use ildasm to determine changes/differences between built assemblies. This works well, but when I try and get it to detect changes in Xaml for (WPF projects), I cannot find any differences - after changes are made to the projects markup.
Any ideas? Am I using this wrong?
Yes XAML files are not compiled to IL and IL stays intact. That's why you don't notice any difference.
XAML files are compiled to BAML(Binary Application Markup Language) and stored as a embedded resource in the assembly itself. For comparing BAML, you need to use BAML Reader.
More on BAML

Is it Possible to Reflect the XAML Markup for VS2012?

I have been looking at some components Microsoft use for VS2012, attempting to learn and use there approaches to extensible component design. Despite being able to decompile the C#, I cannot seem to find any way of looking at the XAML mark-up, is this possible?
Note. I have attempted using Snoop but this does not seem to be able to provide the relevant XAML.
Thanks for your time.
You could use a commercial Reflector with BAML Viewer to convert BAML resource of assembly to XAML.
Also you could use a free dotPeek decompiler. Since 1.1 version it has a feature to view BAML resources without any additional plug-ins.
At last you could use a open source ILSpy decompiler to solve the same problem.

Where to find Generic.xaml for native WPF controls?

Where to find Generic.xaml (or other code with the default look) for native WPF controls such as Button, CheckBox, TextBox, etc?
In Silverlight (and I know that your question is about WPF) this information is more accessible than in WPF. You can get this information from any of these sources:
Control Styles and Templates on MSDN.
You can look at the resources of the relevant Silverlight assembly and extract the themes/generic.xaml embedded in a resource. I use Reflector to do this.
You can extract the control template of a specific control using a tool. I use Expression Blend to do this. This also works for WPF.
Unfortunately the XAML for native controls is not directly available as a file. You need to use a program for peeking into the WPF assemblies and extracting that info. I personally have used the Mole for Visual Studio tool, which has done the job very well. It integrates as a debugger-visualiser, which is quite handy.

What is .baml file?

What is .baml file and what's the use of this file?
Who creates this file?
A compiled XAML file.
Wikipedia says:
A XAML file can be compiled into a
.baml (Binary XAML) file, which may be
inserted as a resource into a .NET
Framework assembly. At run-time, the
framework engine extracts the .baml
file from assembly resources, parses
it, and creates a corresponding WPF
visual tree or workflow.
.baml = Binary Application Markup File, a compiled XAML file.
BAML form is an optimized form of XAML used by the WPF XAML implementation. It is optimized in the sense that it uses internal lookups and tokens for commonly used types or members. The optimization is useful as an implementation detail that addresses packaging size and load time for WPF application scenarios that involve XAML. Full Topic on Msdn
The purpose of BAML is only for checking if generated WPF controls have right values in their properties. Compiled XAML has also its auto-generated *.cs code. You can look at in your app\DEBUG\OBJ directory. Every XAML file has generated cs. Its name is XAMLfileName.g.cs where g means generated.

Resources