What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 130 Stack Exchange communities.

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?

share|improve this question
2  
If the question itself does not explicitly require the c# tag, then you can highlight it yourself using <!-- language: lang-cs --> in front of your code block. –  Bart Aug 29 '12 at 17:49

1 Answer 1

up vote 5 down vote accepted

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 tag has no explicit language hint, so if there is no tag it will highlight both and 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.

share|improve this answer
    
ehm, that works? I said lang-cs –  Bart Aug 29 '12 at 18:00
    
@Bart: Yes, you can use tags as substitute. (If they have an associated language) –  H.B. Aug 29 '12 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 Aug 29 '12 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. –  H.B. Aug 29 '12 at 18:02
    
@H.B. Ha, you learn something new every day. :) –  Bart Aug 29 '12 at 18:02
    
Ah I see, well question still stands, could it just always highlight both (to avoid these cases)? –  KDiTraglia Aug 29 '12 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. –  H.B. Aug 29 '12 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 Aug 29 '12 at 18:07
    
@KDiTraglia: You're welcome, i shall add that to my answer... –  H.B. Aug 29 '12 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .