使用DataTemplate将View连接到ViewModel [英] connect View to ViewModel with DataTemplate

查看:43
本文介绍了使用DataTemplate将View连接到ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解.当我像这样将View连接到ViewModel时:

I'm trying to understand. When I'm connecting View to ViewModel like this:

    <DataTemplate DataType="{x:Type local:MyViewModel}">
        <local:MyView />
    </DataTemplate>

是什么意思?

似乎将View设置为ViewModel的DataTemplate.但是ViewModel没有DataTemplate的属性.那到底是怎么回事?

It looks like the View is set to be the DataTemplate of the ViewModel. BUT the ViewModel doesn't have a Property of DataTemplate. So what exactly is going on in there?

问题的演示-如何通过代码做到这一点(以这种特定方式连接View和ViewModel.我无法编写ViewModel.DataTemplate = View)?

A demonstration of the question - How do I do that by code (Connecting the View and ViewModel this specific way. I can't write ViewModel.DataTemplate = View)?

谢谢.

推荐答案

它的意思是对于内容数据为MyViewModel的任何控件,请将MyView放在此处."您没有在设置viewmodel的DataTemplate(这并不意味着什么),而是在为Data为MyViewModel的控件设置DataTemplate.

It means "To whatever control whose Content data is MyViewModel place MyView there". You are not setting DataTemplate of viewmodel (That does not mean anything) you are setting the DataTemplate for the control whose Data is MyViewModel.

这篇关于使用DataTemplate将View连接到ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆