1

我正在尝试使用 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>

我尝试使用支持属性将 SelectedItem 添加到 xaml,但是当我选择项目时没有触发我的设置器。

4

1 回答 1

0

UWPCommunityToolkit 主/详细视图如何获取选定项?

MasterDetailsView 控件以主/细节模式呈现项目。它在“主面板”中显示项目的集合,并在“详细信息面板”中显示该项目的详细信息。

这样详细信息面板将显示当前选定的项目。您只需要将此项目的详细信息绑定到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 示例

于 2017-04-01T01:20:02.350 回答