Thursday 14 March 2019

Create custom directives

Visual studio projects come with two predefined directives "DEBUG" and "TRACE", there is no RELEASE directive defined. Visual studio projects also come with two configurations namely "Debug" and "Release"; when working with xaml I create a third configuration "Design" I do this so that i can have two sets of view models, design ones with static values and dev ones for whoever is building the ViewModels helping to facilitate parallelism between building the logic and the views.

To do this firstly add a "Design" configuration:
Build->Configuration Manger

once you have the Configuration Manager window open

add a new configuration 

for that new configuration give it the name "Design" and copy the settings from debug.

Click "OK" and your new Solution Configuration will be created

to ensure that it was created check under your solutions configuration dropdown menu 

with that done next open up your project properties
Project -> <Project namespace> properties

next on the project properties window in the "Conditional compilation symbols" textbox enter in DESIGN

once that's done just hit save. 

now in your c# you have access to a "DESIGN" directive letting you write code like the following

            //create Navigation service with design time view models
            //create Navigation service with dev time view models

One caveat is that you have to add your custom "DESIGN" directive to all relevant projects within your solution.

this can be used to create a navigation service that only contains Design time ViewModels so that views can be developed with design time data while ViewModels are developed and as long as the two implement the same interface the two should seamlessly merge.