Is this XAML code possible?

。_饼干妹妹 提交于 2020-01-06 19:30:55

问题


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?


回答1:


Figured it out:

<Binding Source="{StaticResource viewModel}" />

Hope this helps someone.



来源:https://stackoverflow.com/questions/4905007/is-this-xaml-code-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!