开发者

How are views constructed in Josh Smith's MVVM sample?

开发者 https://www.devze.com 2022-12-22 15:57 出处:网络
Being new to both WPF and MVVM, I\'m studying Josh Smith\'s article on the MVVM pattern and the accompanying sample cod开发者_JAVA百科e.

Being new to both WPF and MVVM, I'm studying Josh Smith's article on the MVVM pattern and the accompanying sample cod开发者_JAVA百科e.

I can see that the application is started in app.xaml.cs by constructing a MainWindow object, wiring it to a MainWindowViewModel object and then showing the main window. So far so good.

However, I can't find any code which instantiates the AllCustomersView or CustomerView classes. Using "find all references" on the constructors of those views comes up with nothing. What am I missing here?


WPF's DataTemplate is doing the magic. For example when you set content of a Contentcontrol with an instance of CustomerViewModel with the below DataTemplate in your resource dictionary (usually in app.xaml). Then you are gonna see CustomerView usercontrol coming up in the UI.

<DataTemplate DataType="{x:Type vm:CustomerViewModel}">
  <vw:CustomerView />
</DataTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号