为什么 Microsoft 添加设计时属性 (d:DataContext ...) 而不是使用当前的 DataContext

发布于 2024-09-08 20:23:51 字数 306 浏览 0 评论 0原文

在 WPF-XAML 中,在设计时与运行时确定 DataContext。

为什么我们已经设置了“DataContext”还要添加“d:DataContext”? 当 Microsoft 已经可以使用“DataContext”属性自动确定 DesignTime 属性时,为什么要引入 DesignTime 属性(我们必须添加的代码,有点复杂)。我能看到的唯一实用程序是在运行时在代码中设置 DataContext。否则,Microsoft 可以使用 DataContext 并查找数据的“形状”,就像使用 d:DataContext 一样。

我不明白什么?我缺少什么?

In WPF-XAML, determining DataContext at designtime vs runtime.

Why do we have to add "d:DataContext" while we already have set the "DataContext" ?
Why Microsoft introduced DesignTime attributes (code that we have to add, a little bit complex) when it could already be determined automatically by itself using "DataContext" attribute. The only utility that I could see is for a DataContext set in code at RunTime. Otherwise Microsoft could use the DataContext and find the "Shape" of the data like it does with d:DataContext.

What I don't understand properly ? What I'm missing ?

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

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

发布评论

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

评论(1

孤独患者 2024-09-15 20:23:51

正如您自己指出的:
在许多项目/方法中,DataContext 将在运行时动态设置。
所以你在设计时无法了解有关 DataContext 的任何信息。

As yo noted yourself:
In many projects/approaches the DataContext will be set dynamically at runtime.
So you couldn't know anything about the DataContext at designtime..

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