簡體   English   中英

mscorlib.ni.dll中發生類型'System.Reflection.TargetInvocationException'的異常,但未在用戶代碼中處理:Xamarin形式

[英]An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll but was not handled in user code: in Xamarin Form

我以Xamarin形式創建了MasterDetailPage,但是當我嘗試運行該應用程序時,出現了以上錯誤。 以下是我的MasterDetailPage的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"
         xmlns:pages="clr-namespace:App2;assembly=App2"
         x:Class="App2.ParentsMenuPage">
<MasterDetailPage.Master>
<pages:ParentMasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
  <x:Arguments>
    <pages:ParentHomePage />
   </x:Arguments>
  </NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>


 The Xaml code for My Master Page is below


 <?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="App2.ParentMasterPage" Padding="0,40,0,0">
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand">
  <ListView x:Name="listView" VerticalOptions="FillAndExpand" SeparatorVisibility="None">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" />
      </DataTemplate>
    </ListView.ItemTemplate>
   </ListView>
  </StackLayout>
</ContentPage.Content>

母版頁的代碼如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace App2
{
public class ParentMasterItem
{
    public string Title { get; set; }
    public string IconSource { get; set; }
    public Type TargetType { get; set; }
}

public partial class ParentMasterPage : ContentPage
{
    public ListView ListView { get { return listView; } }

    public ParentMasterPage()
    {
        InitializeComponent();

        var masterPageItems = new List<ParentMasterItem>();
        masterPageItems.Add(new ParentMasterItem
        {
            Title = "Home",
            IconSource = "images/home-small.png",
            TargetType = typeof(ParentHomePage)
        });
        masterPageItems.Add(new ParentMasterItem
        {
            Title = "My Ward's",
            IconSource = "images/ward-small.png",
            TargetType = typeof(ParentWardsPage)
        });
        masterPageItems.Add(new ParentMasterItem
        {
            Title = "Chat",
            IconSource = "images/chat-small.png",
            TargetType = typeof(ParentChatPage)
        });

        listView.ItemsSource = masterPageItems;
       }
      }
    }

然后是詳細頁面

 <?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="App2.ParentHomePage">

 <ContentPage.Content>
   <StackLayout>
    <StackLayout.Children>
     <Frame OutlineColor="Accent">
       <Frame.Content>
         <StackLayout Orientation="Horizontal">
          <StackLayout.Children>
            <Label Text="Home Page"
                   VerticalOptions="Center" />
          </StackLayout.Children>
         </StackLayout>
       </Frame.Content>
     </Frame>

  </StackLayout.Children>
</StackLayout>
</ContentPage.Content>
</ContentPage>

請任何人能幫助我找出問題所在

  1. MyMasterPage應該有一個標題。
  2. 考慮在MasterDetailsPage.Master標記內,內容頁面應具有標題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM