If NETFX_CORE is for Windows 8, what is for Windows Phone 8?

♀尐吖头ヾ 提交于 2019-12-08 19:47:38

问题


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?


回答1:


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.




回答2:


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:

  1. Right click on the WP 8 project and select Properties. Open up the
  2. 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 



回答3:


As far I know, there is not such directive. But you can use if not :

#if !NETFX_CORE 
    // Windows Phone 8
#endif



回答4:


But is there a directive specific to Windows Phone 8?

You can define your own preprocessor directives you know. WINDOWS_PHONE just happens to be defined by the Visual Studio project templates for Windows Phone projects.

Same goes for DEBUG, TRACE and whatever custom ones you might have like EXTENSIVE_LOGGING or LOOKING_FOR_A_CATBUS



来源:https://stackoverflow.com/questions/13594472/if-netfx-core-is-for-windows-8-what-is-for-windows-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!