A minimal example demonstrating how to use Markup Extensions to handle compile-time conditional XAML content in WPF applications.
This project demonstrates how to:
- Create a custom Markup Extension for conditional XAML content
- Use preprocessor directives to control content at compile time
- Avoid XAML duplication and visibility bindings
<Button Content="{local:FeatureCondition
WhenEnabled='New Content',
WhenDisabled='Original Content'}" />
Build original version:
msbuild.exe MarkupExtensionDemo.csproj
Build with new feature enabled:
msbuild.exe MarkupExtensionDemo.csproj /p:DefineConstants="fix_issue_001"
- Visual Studio 2019
- .NET Framework
- WPF
- Clean the solution between builds when switching preprocessor directives
- The example shows both simple text switching and a counter increment (by 1 or 2)
- Uses MarkupExtension for cleaner, more maintainable conditional XAML