使用 DataTemplate 进行动态视图绑定

发布于 2024-10-09 02:00:33 字数 237 浏览 0 评论 0原文

我试图在链接到上面 MainView 代码的 MainViewModel 代码中动态绑定视图。 如何动态绑定数据类型和 vw:SomeView?

<DataTemplate DataType="{Binding GetViewModel}" Resources="{Binding GetView}">
<!--<vw:SomeView/>-->
</DataTemplate>

I am trying to bind view dynamically in code of MainViewModel linked to above MainView's code.
How can I bind datatype and vw:SomeView dynamically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独行侠 2024-10-16 02:00:33

DataTemplate.DataType 属性不是依赖项属性,因此您无法绑定到其值:

http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx

通常,您将在 XAML 中定义多个 DataTemplate 实例,这些实例描述您的 UI渲染每个视图模型。然后,当控件尝试呈现该类型的视图模型时,框架会负责使用这些 DataTemplate。

The DataTemplate.DataType property is not a dependency property so you cannot bind to its values:

http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.datatype.aspx

Typically you will have multiple DataTemplate instances define in your XAML which describe how your UI renders each view model. The framework then takes care of using these DataTemplates when a control tries to render a view model of that type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文