4

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
  • 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. Commented Aug 29, 2012 at 17:49

1 Answer 1

5

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.