The method illustrated in the related question / answer may go some way to providing conditional processing of XAML elements, but I don't think it will give you exactly what you need.
There are two more options that may better suit your needs: software conditional compilation and conditional inclusion at build time.
For programmatic conditional compilation, you can use regular conditional compilation in the code behind your view (preferable since it is a user interface element that you touch) or in view mode (not so clean, but quite acceptable if you need to enable this in several layers) . This conditional compilation can be used to change the values ββreturned from the properties (by changing those lines that were compiled and therefore executed) or by excluding blocks of code (this is inconvenient, but still effective), then you can have a XAML DataTrigger, which has an expression depending on conditionally compiled code .
Another option is to specify control templates in the XAML resource file and either select them programmatically or use the MSBuild property in the ItemGroup in the proj file to control which files are included in the assembly. Combined with the usual software conditional compilation in your models / view models, this should give you a good clean solution for your problem - in fact, using this option, you might not even need program conditional compilation.
The Selector pattern can also help, but IMVHO it's a little dirty to crack. The TemplateSelector is supposed to replace the template based on the type, but you can also use it to include additional code to determine which template to use - this may be a good place to include conditionally compiled code.
slugster
source share