为什么 Microsoft 添加设计时属性 (d:DataContext ...) 而不是使用当前的 DataContext
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您自己指出的:
在许多项目/方法中,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..