开发者

Is this XAML code possible?

开发者 https://www.devze.com 2023-02-08 11:28 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消