Very often when questions are tagged as WPF, I find myself putting little snippets of C# into the answer (even if the question itself is specified in purely xaml, occasionally some C# makes a better solution). However, after making my answer I always notice the C# code doesn't highlight, and I have to edit the C# tag into the question. Couldn't it be implied by the WPF tag that both C# code and xaml code should be highlighted, or should I just continue to add the C# tag to questions if I have any C# in my answer?
1 Answer
Couldn't it be implied by the WPF tag that both C# code and xaml code should be highlighted?
No, because many different languages can be used for the code-behind (C#, F#, VB.NET, Python, ...).
This is why the wpf tag has no explicit language hint, so if there is no xaml tag it will highlight both c# and xaml via language detection. If either of those two (or any other tag with an associated language) is used, only the associated language is highlighted.
So you can retag or as noted by Bart use an explicit hint:
<!-- language: c# -->
See this question for a more in-depth explanation of language hints.
-
-
@Bart: Yes, you can use tags as substitute. (If they have an associated language)brunnerh– brunnerh2012-08-29 18:01:01 +00:00Commented Aug 29, 2012 at 18:01
-
Are you sure that is how it works? I just answered this question a few minutes ago stackoverflow.com/questions/12160618/… and it did not highlight my c# code until I added the tag.KDiTraglia– KDiTraglia2012-08-29 18:01:27 +00:00Commented Aug 29, 2012 at 18:01
-
@KDiTraglia: That's mvvm's fault, it has XML associated as well. Any tag with an explicit language will override the highlighting.brunnerh– brunnerh2012-08-29 18:02:17 +00:00Commented Aug 29, 2012 at 18:02
-
@H.B. Ha, you learn something new every day. :)Bart– Bart2012-08-29 18:02:51 +00:00Commented Aug 29, 2012 at 18:02
-
Ah I see, well question still stands, could it just always highlight both (to avoid these cases)?KDiTraglia– KDiTraglia2012-08-29 18:04:08 +00:00Commented Aug 29, 2012 at 18:04
-
1@KDiTraglia: No, that is the whole point why it has no association, code in a WPF question can be XML + pretty much anything, ranging from C#, F#, vb.net to Python.brunnerh– brunnerh2012-08-29 18:05:56 +00:00Commented Aug 29, 2012 at 18:05
-
Oh that's a good point I didn't think about (in my box it's always C#). Thanks for the answer.KDiTraglia– KDiTraglia2012-08-29 18:07:45 +00:00Commented Aug 29, 2012 at 18:07
-
@KDiTraglia: You're welcome, i shall add that to my answer...brunnerh– brunnerh2012-08-29 18:12:08 +00:00Commented Aug 29, 2012 at 18:12
<!-- language: lang-cs -->in front of your code block.