0

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 ;)

4

2 回答 2

7

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.

于 2010-01-07T20:05:24.587 回答
2

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...

于 2010-01-07T20:04:10.053 回答