我试图实现导航抽屉/主机细节,但我收到此错误,但我看到我的代码没问题,我甚至将我的Xamarin.Forms升级到2.4,但仍然面临这个错误:
print(pick_function(1))
args: (5, (1, 2, 3))
7
完整的错误列表:
local:MasterPage not found in xmlns clr-namespace:Diabetics;assembly=Diabetics
我的MasterPageDetail课程Xamarin.Forms.Xaml.XamlParseException: Position 7:6. Type local:MasterPage not found in xmlns clr-namespace:Diabetics;assembly=Diabetics
at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x00040] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\CreateValuesVisitor.cs:58
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000b1] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:175
at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00054] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:223
at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydratationContext visitorContext) [0x00053] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlLoader.cs:122
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml) [0x00046] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlLoader.cs:76
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type callingType) [0x0002f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlLoader.cs:56
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.Type callingType) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\ViewExtensions.cs:36
at Diabetics.MainActivity.InitializeComponent () [0x00001] in /Users/haleem/Projects/Diabetics/iOS/obj/iPhoneSimulator/Debug/Diabetics.iOS.Main.MainActivity.xaml.g.cs:22
at Diabetics.MainActivity..ctor () [0x00008] in /Users/haleem/Projects/Diabetics/Diabetics/Main/MainActivity.xaml.cs:13
at Diabetics.App..ctor () [0x0000f] in /Users/haleem/Projects/Diabetics/Diabetics/App.xaml.cs:16
at Diabetics.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00007] in /Users/haleem/Projects/Diabetics/iOS/AppDelegate.cs:16
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/4991/4a279c9a/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/4991/4a279c9a/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at Diabetics.iOS.Application.Main (System.String[] args) [0x00001] in /Users/haleem/Projects/Diabetics/iOS/Main.cs:17
MainActivity.cs
然后我的Xaml为using System;
using System.Collections.Generic;
using Diabetics.Models;
using Xamarin.Forms;
namespace Diabetics
{
public partial class MainActivity : MasterDetailPage
{
public MainActivity()
{
InitializeComponent();
masterPage.ListView.ItemSelected += OnItemSelected;
/*
if (Device.RuntimePlatform == Device.Windows)
{
MasterBehavior = MasterBehavior.Popover;
}
*/
}
void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MasterPageItem;
if (item != null)
{
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
masterPage.ListView.SelectedItem = null;
IsPresented = false;
}
}
}
}
:
MainActivity.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:local="clr-namespace:Diabetics;assembly=Diabetics"
x:Class="Diabetics.MainActivity">
<MasterDetailPage.Master>
<local:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:HomeActivity />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
课程:
MasterPage.cs
这是using System;
using System.Collections.Generic;
using Diabetics.Models;
using Xamarin.Forms;
namespace Diabetics
{
public partial class MasterPage : ContentPage
{
public ListView ListView { get { return listView; } }
public MasterPage()
{
InitializeComponent();
var masterPageItems = new List<MasterPageItem>();
masterPageItems.Add(new MasterPageItem
{
Title = "Today",
IconSource = "resorts.png",
TargetType = typeof(Today)
});
masterPageItems.Add(new MasterPageItem
{
Title = "Therapy",
IconSource = "ic_login.png",
TargetType = typeof(Therapy)
});
masterPageItems.Add(new MasterPageItem
{
Title = "Settings",
IconSource = "ic_login.png",
TargetType = typeof(Settings)
});
listView.ItemsSource = masterPageItems;
}
}
}
:
MasterPage.xaml
答案 0 :(得分:0)
好。我在处理共享项目时遇到了这个挑战,下面是我解决它的步骤,但请记住解决方案中的每个平台都有一个程序集,但是共享项目(你编写的大部分代码)不:
此错误的解决方案只是从xmlns:local字符串中删除assembly=MyAssemblyName
。它应该是xmlns:local="clr-namespace:MyNameSpace;"