繁体   English   中英

Xamarin.form-Masterdetailpage:System.Reflection.TargetInvocationException:调用的目标已引发异常

[英]Xamarin.form - Masterdetailpage : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

我已经使用xamarin.form便携式

当我使用MasterDetailPage时,出现错误:“ System.Reflection.TargetInvocationException:调用的目标引发了异常。”

以下是我的XAML代码

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="SlideNavigation.Page1"
              IsPresented="True">
  <MasterDetailPage.Master>
<ContentPage>
  <ListView x:Name="listview" ItemSelected="Listview_itemSelected">
    <ListView.ItemTemplate>
      <DataTemplate>
        <TextCell Text="{Binding Name}" Detail="{Binding Status}"></TextCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<ContentPage ></ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>

以下是我的.cs代码

public partial class Page1 : MasterDetailPage
{
    public Page1()
    {
        InitializeComponent();

        listview.ItemsSource = new List<Contact>
       {
           new Contact { Name = "Kirti",Status = "True"},
           new Contact { Name = "Nilesh",Status = "False"}
       };
    }
    void Listview_itemSelected(object sender, SelectedItemChangedEventArgs e)
    {

        var contact = e.SelectedItem as Contact;
         Detail = new NavigationPage(new  Page2(contact.Name));
        IsPresented = false;
    }
}

请帮助我我犯错了。

提前致谢

您必须在母版页上设置标题属性

  <MasterDetailPage.Master>
    <ContentPage Title="Content Page">
      <ContentPage.Content>
        <ListView x:Name="listview" ItemSelected="Listview_itemSelected">
          <ListView.ItemTemplate>
            <DataTemplate>
              <TextCell Text="{Binding Name}" Detail="{Binding Status}"></TextCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
      </ContentPage.Content>
    </ContentPage>
  </MasterDetailPage.Master>

暂无
暂无

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

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