简体   繁体   English

UWP主/明细视图

[英]UWP Master/Detail view

I am searching for a good example how to build a master/detail view for UWP Win 10 app like shown on this page: https://msdn.microsoft.com/en-us/library/windows/apps/dn997765.aspx For example Windows Mail app has the same master/detail view. 我正在寻找一个很好的例子,如何为UWP Win 10应用程序构建一个主/详细视图,如本页所示: https//msdn.microsoft.com/en-us/library/windows/apps/dn997765.aspx For示例Windows Mail应用程序具有相同的主/详细视图。 How can I implement this style? 我该如何实现这种风格? On the left side I think to use a listview, but how to show the data in the Detail side? 在左侧我想使用listview,但如何在Detail端显示数据? Can I use a Frame or ContentPresenter? 我可以使用Frame或ContentPresenter吗? How can enable/disable the detail view on phone/tablet/pc? 如何启用/禁用手机/平板电脑/ PC上的详细信息视图? Hope there is example or tutorial which shows how to deal with this. 希望有示例或教程,说明如何处理这个问题。

It's good to have some app architecture... The Windows XAML community already worked on it. 拥有一些应用程序架构是件好事...... Windows XAML社区已经开始研究它了。

https://github.com/Windows-XAML/Template10/tree/master/Samples/MasterDetail https://github.com/Windows-XAML/Template10/tree/master/Samples/MasterDetail

I think: https://blogs.msdn.microsoft.com/johnshews_blog/2015/09/09/a-minimal-mvvm-uwp-app/ is a good exemple. 我想: https//blogs.msdn.microsoft.com/johnshews_blog/2015/09/09/a-minimal-mvvm-uwp-app/是一个很好的例子。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <StackPanel Grid.Column="0" Orientation="Vertical">
        <ListView x:Name="MainList"
            ItemsSource="{x:Bind Organization.People, Mode=OneWay}"
            SelectedIndex="{x:Bind Organization.SelectedIndex, Mode=TwoWay}"
            MinWidth="250" Margin="5">

            <ListView.ItemTemplate>
                <DataTemplate x:DataType="viewModels:PersonViewModel" >
                    <TextBlock Text="{x:Bind Name, Mode=OneWay}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>

    <StackPanel Grid.Column="2" Orientation="Vertical">
        <TextBox
            Text="{x:Bind Organization.SelectedPerson.Name, Mode=TwoWay, FallbackValue=''}"
            Margin="5" />
        <TextBox
            Text="{x:Bind Organization.SelectedPerson.Age, Mode=TwoWay, FallbackValue='0'}"
            Margin="5" />
    </StackPanel>
</Grid> 

You can also find another exemple in samples app : https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlListView 您还可以在示例应用中找到另一个示例: https//github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlListView

您还可以使用UWP Community Toolkit提供的MasterDetailsView控件。

You can use region frames. 您可以使用区域框架。 Here is an example for MvvmCross. 这是MvvmCross的一个例子。

<SplitView x:Name="RootSplitView"
           DisplayMode="Inline"
           OpenPaneLength="256"
           IsTabStop="False">
    <SplitView.Pane>
        <StackPanel Margin="0,50,0,0">
            <Button Content="Second" Command="{x:Bind Vm.SecondCommand}" />
            <Button Content="Third" Command="{x:Bind Vm.ThirdCommand}" />
        </StackPanel>
    </SplitView.Pane>

    <!-- OnNavigatingToPage we synchronize the selected item in the nav menu with the current page.
         OnNavigatedToPage we move keyboard focus to the first item on the page after it's loaded and update the Back button. -->
    <Frame x:Name="FrameContent">
        <Frame.ContentTransitions>
            <TransitionCollection>
                <NavigationThemeTransition>
                    <NavigationThemeTransition.DefaultNavigationTransitionInfo>
                        <EntranceNavigationTransitionInfo/>
                    </NavigationThemeTransition.DefaultNavigationTransitionInfo>
                </NavigationThemeTransition>
            </TransitionCollection>
        </Frame.ContentTransitions>
    </Frame>
</SplitView>

In the code behind file add 在代码后面的文件中添加

public Frame AppFrame { get { return (Frame)this.WrappedFrame.UnderlyingControl; } }

Add this in setup.cs file 在setup.cs文件中添加它

protected override IMvxWindowsViewPresenter CreateViewPresenter(IMvxWindowsFrame rootFrame)
{
    return new MvxWindowsMultiRegionViewPresenter(rootFrame);
}

for newer versions use: 对于较新版本使用:

protected override IMvxWindowsViewPresenter CreateViewPresenter(IMvxWindowsFrame rootFrame)
{
    return new MvxWindowsMultiRegionViewPresenter(rootFrame);
}

Add following attribute at the top of the code behind file of child view: 在子视图的代码隐藏文件的顶部添加以下属性:

[MvxRegion("FrameContent")]

For later versions: 对于更高版本:

[MvxRegionPresentation("FrameContent")]

Use this for navigating to child view: 用它来导航到子视图:

ShowViewModel<SecondViewModel>()

Refer to this link: https://depblog.weblogs.us/2015/11/23/mvvmcross-uwp-splitview/ 请参阅此链接: https//depblog.weblogs.us/2015/11/23/mvvmcross-uwp-splitview/

Examples: https://github.com/MvvmCross/MvvmCross-Samples/tree/master/XPlatformMenus 示例: https//github.com/MvvmCross/MvvmCross-Samples/tree/master/XPlatformMenus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM