这个XAML代码是否可行? [英] Is this XAML code possible?
本文介绍了这个XAML代码是否可行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< navigation:Page.Resources>
< local:ProposalViewModel x:Key =viewModel/>
< / navigation:Page.Resources>
< navigation:Page.DataContext>
<! - 绑定到从viewModel公开的viewmodel - >
< / navigation:Page.DataContext>
有些语句可以用来放入Page.DataContext绑定,以便它指向与静态资源相同的实例?
解决方案
想出来:
< Binding Source ={StaticResource viewModel}/>
希望这有助于某人。
I have a silverlight app that I'm trying to keep as MVVM as possible. I'm trying to set the datacontext of the page from a static resource on the page (so that I can reference the static resource later in a datagrid). But I'm having problems getting this to work. Is the following code possible?
<navigation:Page.Resources>
<local:ProposalViewModel x:Key="viewModel" />
</navigation:Page.Resources>
<navigation:Page.DataContext>
<!-- Binding to the viewmodel exposed from 'viewModel' -->
</navigation:Page.DataContext>
Is there some statement that I can use to put into the Page.DataContext binding so that it points at the same instance as the static resource?
解决方案
Figured it out:
<Binding Source="{StaticResource viewModel}" />
Hope this helps someone.
这篇关于这个XAML代码是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文