- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前我有一些 View 使用类似于以下的代码链接到 ViewModels:
<Application.Resources>
<DataTemplate DataType="{ x:Type vm:AgeIndicatorViewModel}">
<v:AgeIndicatorView />
</DataTemplate>
</Application.Resources>
我有两个问题:
此方法是否允许我仅将一个 View 链接到每个 View 模型(我认为它确实对我施加了此限制,但想确定一下)
使用此方法时,我应该将所有 DataTemplate 声明放在哪里?目前只有少数几个,它们都在 App.Xaml 中 - 是否有更好的位置,或者 App.Xaml 是否合适/最佳位置?
最重要的问题确实是第二个,因为目前我想以这种方式将我的 ViewModel 链接到我的 View,因为它不需要外部库等。
我的 ViewModels 的设置方式、它们的属性和命令等都已经可以正常工作了。
最佳答案
Does this method allow me to only link one View to each View Model (I think it does improse this limitation on me, but want to be sure)
是的。如果您尝试将多个 ViewModel 链接到多个 View ,您需要将它们封装在一个单独的 VM 中,并添加一个新的 DataTemplate。
When using this method, where should I put all of my DataTemplate declarations? At the moment there are only a few, and they are all in App.Xaml - Is there a better location for these, or is App.Xaml fine / Best location?
App.Xaml 很好,或者实际上是可视层次结构中将使用 DataTemplate 的任何地方。
话虽这么说,如果项目成为一个非常大规模的项目,开始使用 Merged Resource Dictionaries 通常会更好。 - 这允许您在定义 View/ViewModel 对的位置“附近”设置资源字典,然后在更高级别使用它们(即:将它们合并到 App.Xaml 中)。
关于wpf - 使用 MVVM 模式的 WPF 应用程序的 DataTemplate 将 View 链接到 ViewModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6784091/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!