zoukankan      html  css  js  c++  java
  • 从PRISM开始学WPF(番外)共享上下文 RegionContext-更新至Prism7.1

    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.

    RegionContext

    (⊙﹏⊙)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)

  • 相关阅读:
    测试网站的响应性的工具
    取出分组后的前N条数据,笔记记录。
    纯js制作页码导航
    英语单复数转换类
    用鼠标滚动缩放图片
    Plugin 'InnoDB' init function returned error.Could not start the service MySQL 解决方法
    超时时间已到。在操作完成之前超时时间已过或服务器未响应。
    数据库关系图”提示:此数据库没有有效所有者(转载)
    关于非静态类的静态成员与非静态成员的初始化顺序(zhuang)
    项目经理的“势能”培养 (转)
  • 原文地址:https://www.cnblogs.com/hicolin/p/8742690.html
Copyright © 2011-2022 走看看