Conditional compilation symbols access from XAML file?

JonAlzaJonAlza ESMember ✭✭

Is it possible to access conditional compilation symbols from XAML? I know that I can do things in code behind, but I want know if it is possible to do it from XAML.

I need to show an Entry or a Picker depending on this symbol.


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Interesting but I think it is not possible... use code behind
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I need to show an Entry or a Picker depending on this symbol.

    Set the IsVisible property, binded to a property in your ViewModel.
    If you want to do that with a debug symbol, set that in your property

    <Picker IsVisible = "{binding IsDebug}"/>
    bool  IsDebug
       get {
          #if DEBUG
             return true;
       return false;
  • JonAlzaJonAlza ESMember ✭✭

    Thank you for the answers.

    @AlessandroCaliaro I will wait until someone responds that it is certainly not possible.

    @ClintStLaurent As I said in the first post "I know that I can do things in code behind" and I did, but the question is about accessibility of the compilation symbols directly from XAML

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I think that was already addressed. But I'll be more clear.
    No. There is no handling of pre-compile directives in XAML.
    XAML is not code. It doesn't execute. So it doesn't compile to code. Therefore pre-compile directives have no effect in XAML.

    It was really unclear what you meant by "do stuff in code behind". So I tried to give you an example of how you can handle the need you described using binding. Not sure of that qualifies as "stuff". But it is MVVM pattern and is not C# code behind micromanaging XAML UI elements.

    I hope that clears things up.

  • JonAlzaJonAlza ESMember ✭✭

    Thank you @ClintStLaurent , you are right, I have confused MVVM code with code behind. Sorry. But when someone sais "I think" it is not "I am sure".

    But I disagree when you say that XAML does not execute. Every XAML when it is used is loaded in the constructor, in the InitializeComponent() method. And maybe there is a way to do it. In WPF there is a way (but is is using namespaces, not compilation symbols).

    Also you can compile XAML files, in order to increase performance, so I don't lose hope.

  • tossingctossingc USMember, Beta, University
    edited August 2018

    @JonAlza XAML Conditional Compilation (XCC)

    The forum won't let me post links yet, but links are below with spaces inserted. You can also google xcc nuget

    htt ps://

    htt ps://

    cc: @ClintStLaurent @AlessandroCaliaro

Sign In or Register to comment.