作为WPF和MVVM的新手,我正在研究Josh Smith关于MVVM模式和随附示例代码的文章.
我可以看到应用程序是app.xaml.cs通过构造一个MainWindow对象,将它连接到一个MainWindowViewModel对象然后显示主窗口来启动的.到现在为止还挺好.
但是,我找不到任何实例化AllCustomersView或CustomerView类的代码.在这些视图的构造函数上使用"查找所有引用"没有任何结果.我在这里错过了什么?
WPF的DataTemplate正在发挥作用.例如,当您在资源字典中使用具有以下DataTemplate的CustomerViewModel实例设置Contentcontrol的内容时(通常在app.xaml中).然后,您将在UI中看到CustomerView用户控件.
<DataTemplate DataType="{x:Type vm:CustomerViewModel}">
<vw:CustomerView />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)