Question

Given the following two options:

<ContentControl>Content</ContentControl>

vs.

<ContentControl Content="Content"/>
  1. Any performance differences?
  2. What would you say is more readable?
  3. Conclusion?

I'm affraid this question might sound somehow babyish, but how will I know if I won't ask, so I decided to shoot it.
Comment me if I chose the wrong decision ;)

Was it helpful?

Solution

Just as a personal preference, I vote for

<ContentControl Content="Content"/>

but only because I find it more readable. AFAIK there is no performance impact by choosing one or the other, but I haven't done any testing to substantiate that...

OTHER TIPS

The two are identical, in terms of what is generated. The performance will be identical.

The first option, however, let's you put something that isn't directly generated via a simple text string or a markup extension, such as:

<ContentControl>
  <StackPanel>
    <TextBlock Text="Content" />
    <Image Source="SomeImage.png" />
  </StackPanel>
</ContentControl> 

If, however, you're only putting in a single text string, I find the second more readable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top