C# – How to decompile complex BAML to valid XAML

bamlcwpfxaml

I tried ILSpy, but it failed:

System.NotImplementedException: StaticResourceStart
   в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ProcessNext()
   в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.ReadInternal()
   в Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.Read()
   в System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   в System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   в System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   в ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
   в ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadBaml(AvalonEditTextOutput output)
   в ILSpy.BamlDecompiler.BamlResourceEntryNode.<>c__DisplayClass3.<View>b__1()

I tried Baml Viewer for .Net Reflector, but it was unable to generate valid XAML.

The main problem was with Binding that reference to wrong StaticResource.

For example (namedViews is CollectionViewSource):

   Visibility="{Binding Path=Value, Converter={StaticResource namedViews}}"
   ToolTip="{StaticResource namedViews}"

What other applications exist to decompile BAML? Any patch to BAML Viewer?

Best Answer

Not sure if this will help you, but if you can run the application, you can use Snoop to run through the structure of a WPF application.

Other options:

I've only tried Snoop and like it very much, but that didn't seem to solve your problem.