Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Conditional Compilation in XAML

Conditional Compilation in XAML

Scheduled Pinned Locked Moved WPF
wpftutorialquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vivasaayi
    wrote on last edited by
    #1

    I want to use Conditional Compilation Directives (#if, #endif) in my XAML file as well as in the codebehind file. Can anybody provide me links or sample code? Is there any other technique to do the same? Please guide me. ex.

    #if TASK
    Add Task
    #else
    Add Contact
    #endif

    P 1 Reply Last reply
    0
    • V vivasaayi

      I want to use Conditional Compilation Directives (#if, #endif) in my XAML file as well as in the codebehind file. Can anybody provide me links or sample code? Is there any other technique to do the same? Please guide me. ex.

      #if TASK
      Add Task
      #else
      Add Contact
      #endif

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You can only use the Conditional Compilation Directives in code behind. As you can see, they are not valid XML, so they are not suitable for use in XAML. From the look of the quick sample you've posted, you might want to use DataTemplates, Template Selectors and the MVVM pattern. Have a look at Josh Smith's article on MSDN to get a better understanding of this.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      V 1 Reply Last reply
      0
      • P Pete OHanlon

        You can only use the Conditional Compilation Directives in code behind. As you can see, they are not valid XML, so they are not suitable for use in XAML. From the look of the quick sample you've posted, you might want to use DataTemplates, Template Selectors and the MVVM pattern. Have a look at Josh Smith's article on MSDN to get a better understanding of this.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        V Offline
        V Offline
        vivasaayi
        wrote on last edited by
        #3

        Can you please provide me the link?

        P 1 Reply Last reply
        0
        • V vivasaayi

          Can you please provide me the link?

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          I can do better than that - I can give you an idea of how I think, which hopefully means you can perform the same actions as me in future. This should mean that you don't have to wait for others to give you answers, instead you will be able to do your own research, saving you time, and increasing your effectiveness as a developer. First of all, I thought to myself - how can I find the link to this article? I can't remember the URL of this article, but I can think of some mechanism which will allow me to look something up off the internet. So, once I've ascertained that I can't remember the URL directly, I know that I need to look it up from a search engine. At this point, I need to think of the keywords that will help me perform an effective search. Well, we know that the article was written by Josh Smith, we also know it was written for the MSDN magazine and it was about MVVM, so I can make an educated guess at the keywords; namely Josh Smith MVVM MSDN magazine. A quick hop on over to Google and I enter these keywords, hit search and what do you know, the first result is the one I want[^]. When you can think how to search for answers yourself, and not rely on others to do the searching for you, you will be able to make drastic leaps forward in your effectiveness and ability as a developer.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          L 1 Reply Last reply
          0
          • P Pete OHanlon

            I can do better than that - I can give you an idea of how I think, which hopefully means you can perform the same actions as me in future. This should mean that you don't have to wait for others to give you answers, instead you will be able to do your own research, saving you time, and increasing your effectiveness as a developer. First of all, I thought to myself - how can I find the link to this article? I can't remember the URL of this article, but I can think of some mechanism which will allow me to look something up off the internet. So, once I've ascertained that I can't remember the URL directly, I know that I need to look it up from a search engine. At this point, I need to think of the keywords that will help me perform an effective search. Well, we know that the article was written by Josh Smith, we also know it was written for the MSDN magazine and it was about MVVM, so I can make an educated guess at the keywords; namely Josh Smith MVVM MSDN magazine. A quick hop on over to Google and I enter these keywords, hit search and what do you know, the first result is the one I want[^]. When you can think how to search for answers yourself, and not rely on others to do the searching for you, you will be able to make drastic leaps forward in your effectiveness and ability as a developer.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            L Offline
            L Offline
            Lutoslaw
            wrote on last edited by
            #5

            Pete O'Hanlon wrote:

            Google

            Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/[^] Yours sincerely - - Google search engine development team ;P

            Greetings - Jacek

            P 1 Reply Last reply
            0
            • L Lutoslaw

              Pete O'Hanlon wrote:

              Google

              Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/[^] Yours sincerely - - Google search engine development team ;P

              Greetings - Jacek

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Jacek Gajek wrote:

              Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/\[^\]

              Give a man a fish, and he'll eat for a day. Teach a man to fish, and he'll buy expensive rods and dodgy waders. The moral of the story here - it's better to be the supplier to the person who teaches a man to fish; offer sufficient kickbacks and you'll never run out of business.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              V I 2 Replies Last reply
              0
              • P Pete OHanlon

                Jacek Gajek wrote:

                Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/\[^\]

                Give a man a fish, and he'll eat for a day. Teach a man to fish, and he'll buy expensive rods and dodgy waders. The moral of the story here - it's better to be the supplier to the person who teaches a man to fish; offer sufficient kickbacks and you'll never run out of business.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                V Offline
                V Offline
                vivasaayi
                wrote on last edited by
                #7

                Hey man thanks for your reply. However I googled and got the link before you give. I thought you could have given me the idea after searching Google. So the link could be recorded in your browser history. That could save time for me to search again. However I am not looking for Routed Templates. I am looking for conditional Compilation in XAML, in which I can set the Parameters in the Project file and Include/Exclude some XAML output. I followed the article http://www.removingalldoubt.com/commentview.aspx/defa2a7d-b1e9-49eb-b8c8-438348be8d18[^] and solved the problem. I am posting this so that others can also refer to this solution.

                1 Reply Last reply
                0
                • P Pete OHanlon

                  Jacek Gajek wrote:

                  Here is an officialy recommended way to share Google links to your friends: http://lmgtfy.com/\[^\]

                  Give a man a fish, and he'll eat for a day. Teach a man to fish, and he'll buy expensive rods and dodgy waders. The moral of the story here - it's better to be the supplier to the person who teaches a man to fish; offer sufficient kickbacks and you'll never run out of business.

                  "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                  As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                  My blog | My articles | MoXAML PowerToys | Onyx

                  I Offline
                  I Offline
                  Ian Shlasko
                  wrote on last edited by
                  #8

                  Give a man a fish, and he'll eat for a day. Turn a man into a fish, and he'll be eaten for the rest of his life.

                  Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups