TransformXaml parses markup files to identify elements for renaming and updates their corresponding references.
Supported Formats
Transform XAML supports the following markup formats:
| Format | Description |
| XAML | Standard XAML markup files. |
| BAML | Binary XAML used by WPF applications. |
| XBF | Binary XAML format used by UWP and Windows 8.x applications. |
When to Enable Transform XAML
Enable Transform XAML when protecting applications that use supported XAML technologies, including:
- Windows Presentation Foundation (WPF)
- Universal Windows Platform (UWP)
- Other applications that use supported XAML or binary XAML formats
When enabled, Dotfuscator parses the markup files, identifies references to renamed code elements, and updates those references in the protected output.
Configure Transform XAML
You can configure Transform XAML globally or for individual assemblies.
Configure All Assemblies
Use the Transform XAML/BAML resources in all assemblies option () on the toolbar to enable or disable Transform XAML for all input assemblies.
Configure Individual Assemblies
To configure Transform XAML for a specific assembly:
- Open the Config Editor.
- Navigate to the Input tab.
- Locate the assembly in the Input Assemblies list.
- Select the Transform XAML checkbox.
This allows you to enable Transform XAML only for assemblies that contain XAML resources.
Library Mode Considerations
When Library Mode is enabled, Dotfuscator preserves public types by default. As a result, some classes referenced by XAML may not be renamed.
If you want public classes to be renamed, disable Library Mode for the assembly before building.
For more information, see Configure Library Mode.
Example
Consider a simple WPF application WpfSampleApp where a Button UI element changes a TextBox via WPF data binding. The solution structure contains MainWindow.xaml and App.xaml.
Inside MainWindow.xaml, a Grid container holds the TextBox and Button child elements. All three elements use the x:Name attribute for identification:
-
Grid:
testWpfGrid -
TextBox:
txtWpfTextBox -
Button:
btnWpfButton
During protection:
- Dotfuscator renames the corresponding fields and members in the assembly.
- Transform XAML updates the identifiers in the XAML or compiled BAML.
- The protected application continues to function because the markup and assembly remain synchronized.
You can verify the renamed identifiers by doing the following:
-
Review the Map.xml file to see the mapping of original names to new identifier names.
-
View the updated references by opening the obfuscated assembly in the ILSpy decompiler.
-
Check the Field Metadata table in ILSpy to confirm the changed TextBox name.
Note: Public classes like ButtonCommand and MainWindow are not renamed by default. To rename these classes, disable Library Mode in the Config Editor or via the configuration file. For more information, see Configure Library Mode.
-
After disabling Library Mode, use ILSpy to view the updated class names in the obfuscated assembly.
Best Practices
- Enable Transform XAML whenever Renaming is used with supported XAML applications.
- Configure the option only for assemblies that contain XAML resources.
- Test the protected application after building to verify that XAML resources load correctly.
- Review the generated map file when troubleshooting renamed XAML elements.