UWPCommunityToolkit主/详细信息视图如何获取所选项目?

时间:2017-03-31 01:08:40

标签: c# xaml uwp windows-community-toolkit

我正在尝试使用UWPCommunityToolkit中的Master / Detail,我如何才能获得所选项目的详细信息?我用一组匿名对象加载项目:

listOfReplayFiles = await ReplayDirectoryManager.GetAllReplaysFromReplayDirectoryAsync();
        foreach (var item in listOfReplayFiles)
        {
            SavedReplays.Add(new { ReplayName = item.Name, ReplayDateCreated = item.DateCreated });
        }

这就是我的xaml看起来像

        <uwpkit:MasterDetailsView 
        RelativePanel.Below="pageHeader"
        ItemsSource="{Binding SavedReplays}">

        <uwpkit:MasterDetailsView.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{Binding ReplayName}" />

                    <TextBlock Style="{ThemeResource CaptionTextBlockStyle}">
                        <Run Text="Date Created: " />
                        <Run Text="{Binding ReplayDateCreated}" />
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </uwpkit:MasterDetailsView.ItemTemplate>

        <!--<uwpkit:MasterDetailsView.DetailsTemplate>
            <DataTemplate>

            </DataTemplate>
        </uwpkit:MasterDetailsView.DetailsTemplate>-->

    </uwpkit:MasterDetailsView>

我尝试使用backing属性将SelectedItem添加到xaml,但是当我选择项目时不会触发我的setter。

1 个答案:

答案 0 :(得分:0)

  

UWPCommunityToolkit主/详细信息视图如何获取所选项目?

MasterDetailsView控件以主/细节模式显示项目。它显示了&#34;主面板中的一组项目&#34;以及&#34;详细信息面板&#34;中该项目的详细信息。

这样详细信息面板将显示当前所选项目。您只需要将此项目的详细信息绑定到DetailsTemplate即可。例如,在详细信息面板中显示与主面板相同的内容可能如下:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <uwpkit:MasterDetailsView 
    RelativePanel.Below="pageHeader"
    ItemsSource="{Binding}">
        <uwpkit:MasterDetailsView.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{Binding ReplayName}" />
                    <TextBlock Style="{ThemeResource CaptionTextBlockStyle}">
                    <Run Text="Date Created: " />
                    <Run Text="{Binding ReplayDateCreated}" />
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </uwpkit:MasterDetailsView.ItemTemplate>
        <uwpkit:MasterDetailsView.DetailsTemplate>
        <DataTemplate>
                <StackPanel>
                    <TextBlock Style="{ThemeResource TitleTextBlockStyle}" Text="{Binding ReplayName}" />
                    <TextBlock Style="{ThemeResource CaptionTextBlockStyle}">
                    <Run Text="Date Created: " />
                    <Run Text="{Binding ReplayDateCreated}" />
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
    </uwpkit:MasterDetailsView.DetailsTemplate>
    </uwpkit:MasterDetailsView>
</Grid>

更多详情请参考MasterDetailsView sample