简体   繁体   English

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

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

I have using xamarin.form portable 我已经使用xamarin.form便携式

When I using MasterDetailPage I am getting error: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation." 当我使用MasterDetailPage时,出现错误:“ System.Reflection.TargetInvocationException:调用的目标引发了异常。”

Below is my xaml code 以下是我的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>

Below is my .cs code 以下是我的.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;
    }
}

Please help me what I am making mistake. 请帮助我我犯错了。

Thanks in advance 提前致谢

You must set Title property on Master Page 您必须在母版页上设置标题属性

  <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.

相关问题 System.Reflection.TargetInvocationException: &#39;调用的目标已抛出异常 - System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation System.Reflection.TargetInvocationException :调用的目标已抛出异常 - System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation System.Reflection.TargetInvocationException:调用的目标已引发异常 - System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation Xamarin Forms System.Reflection.TargetInvocationException: &#39;调用的目标已抛出异常。&#39; - Xamarin Forms System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.' Xamarin System.Reflection.TargetInvocationException:调用的目标已引发异常 - Xamarin System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation Xamarin 表单:System.Reflection.TargetInvocationException:调用的目标已抛出异常 - Xamarin Forms: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation 为什么我收到异常 System.Reflection.TargetInvocationException: &#39;Exception has been throwed by the target of an invocation.&#39;? - Why I'm getting exception System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'? 使用 Task.Run 时如何修复“System.Reflection.TargetInvocationException: 'Exception has been throwed by the target of an invocation.'” - How to fix “System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'” when use Task.Run 如何修复“System.Reflection.TargetInvocationException已被抛出” - How to fix “System.Reflection.TargetInvocationException has been thrown” TargetInvocationException:调用的目标引发了异常。 关于数据绑定 - TargetInvocationException: Exception has been thrown by the target of an invocation. on Data Bind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM