Is this XAML code possible?
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 refere开发者_Go百科nce 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.
精彩评论