I understand using the NETFX_CORE directive, like this:
#if NETFX_CORE
// Windows 8
#else
// Windows Phone 8
#endif
More info: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714084(v=vs.105).aspx
But is there a directive specific to Windows Phone 8?
Yes, the Windows Phone directive is:
#if WINDOWS_PHONE
This is documented here, but I'm surprised that it isn't mentioned here. I also tested this in some code, and it works.
WP8 should use custom conditional compilation flags introduced by the developer. Read more about this exact topic here. Nokia has an entire article dedicated to coding for both WP7 and WP8 and I highly recommend you go over all techniques to see what's the best one for you to use.
Defining conditional compilation symbol:
- Right click on the WP 8 project and select Properties. Open up the
- Build page of Project Designer and insert WP8 into Conditional compilation symbols. After this, they should contain something like this: SILVERLIGHT;WINDOWS_PHONE;WP8
And here's the inline code sample
// Separate implementations for different OS versions
#if WP8
// code using enhancements introduced in Windows Phone 8
#else
// code using Windows Phone OS 7.1 features
#endif
// A new Windows Phone 8 feature
#if WP8
// code using new Windows Phone 8 feature
#endif
As far I know, there is not such directive. But you can use if not :
#if !NETFX_CORE
// Windows Phone 8
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With