从PRISM开始学WPF(番外)共享上下文 RegionContext-更新至Prism7.1

53 篇文章 5 订阅

RegionContext共享上下文

There are a lot of scenarios where you might want to share contextual information between the view that is hosting a region and a view that is inside a region. For example, a master detail–like view shows a business entity and exposes a region to show additional detail information for that business entity. The Prism Library uses a concept named RegionContext to share an object between the host of the region and any views that are loaded inside the region, as shown in the following illustration.

 

(⊙﹏⊙)Google一下!

有很多场景可能需要在托管区域的视图和区域内的视图之间共享上下文信息。例如,类似主细节的视图显示一个业务实体并公开一个区域以显示该业务实体的附加详细信息。Prism使用一个名为RegionContext的概念在该区域的主机和该区域内加载的任何视图之间共享一个对象,如下图所示。

大意就是,在父视图中,添加一个Region,用来显示扩展信息,并且指定这个Region的DataContext(但是官方说This approach is somewhat similar to the DataContext, but it does not rely on it.),也就是说,仅仅是像而已!也就是说,不不用再为这个即将加载进来的视图,单独设置DataContext,任何一个加载进来的视图都共享这个RegionContext。

    <Grid x:Name="LayoutRoot" Background="White" Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ListBox x:Name="_listOfPeople" ItemsSource="{Binding People}"/>
        <ContentControl Grid.Row="1" Margin="10"
                        prism:RegionManager.RegionName="PersonDetailsRegion"
                        prism:RegionManager.RegionContext="{Binding SelectedItem, ElementName=_listOfPeople}"/>
    </Grid>

上面代码中即是,将_listOfPeople的SelectedItem,作为即将加载到PersonDetailsRegion中的视图的RegionContext

PersonListViewModel的People的元素类型是Person
PersonDetailViewModel的公开属性是SelectedPerson,类型也是Person
这在一些传统应用,含有列表与详细的页面中非常有用。(这个很像winform里的databindings)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值