内容相比

发布于 2024-08-17 06:51:26 字数 306 浏览 4 评论 0原文

给出以下两个选项:

<ContentControl>Content</ContentControl>

vs.

<ContentControl Content="Content"/>
  1. 有性能差异吗?
  2. 您认为什么更具可读性?
  3. 结论?

我担心这个问题听起来有些幼稚,但如果我不问我怎么知道,所以我决定开枪。
如果我选择了错误的决定,请评论我;)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心小果奶 2024-08-24 06:51:26

就生成的内容而言,两者是相同的。性能将是相同的。

然而,第一个选项让您放置一些不是通过简单文本字符串或标记扩展直接生成的内容,例如:

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

但是,如果您只输入单个文本字符串,我发现第二个更具可读性。

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.

若沐 2024-08-24 06:51:26

只是出于个人喜好,我投票支持,

<ContentControl Content="Content"/>

但只是因为我发现它更具可读性。 AFAIK 选择其中之一不会对性能产生影响,但我还没有进行任何测试来证实这一点......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文