Xamarin MasterDetail 数据绑定到所选项目的示例

Example Xamarin MasterDetail Data Binding to Selected Item

我正在通过使用 visual studio 给出的基本 MasterDetail 示例进行测试来学习 Xamarin,当您在解决方案上执行添加 -> 新项目... -> 主详细信息页面时。 In this example the Master Page data binds to a list of items in a view model and when one is selected it displays the detail page.我的问题是默认的详细信息页面是空的,没有显示如何绑定到所选项目。所以我的问题是如何修改这个基本的详情页..

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App.WireFrameDetail"
             Title="Detail">
    <StackLayout Padding="10">
        <Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
    </StackLayout>
</ContentPage>

我想做的只是绑定到在母版页上选择的项目并在标签文本中显示标题 属性 来表达类似 "This is a detail page for {Binding Title}." 我试过很多东西,但似乎这个页面默认没有数据绑定,我怀疑它需要作为 ItemSelected 过程的一部分注入,但我希望它会被框架自动绑定。

所以我的问题是,我需要添加什么来完成对母版页上所选项目的简单绑定?

正如其他人在评论中发布的那样,执行此操作的方法是通过构造函数、参数传递和绑定注入。这些概述如下: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/hierarchical/#Passing_Data_when_Navigating