【问题标题】:Xamarin.Forms.Xaml.XamlParseException exception in XamarineformsXamarinforms 中的 Xamarin.Forms.Xaml.XamlParseException 异常
【发布时间】:2019-11-11 17:45:30
【问题描述】:

我是 Xamarine 的新手。 我在 Visual Studio 2019 中创建了新的空白 Xamarine 项目。 我正在使用此链接以 Xamarine 表单创建演示本机视图:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-views/xaml

MainPage.Xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
             xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
             xmlns:androidLocal="clr-namespace:App1.Android;assembly=App1.Android;targetPlatform=Android"
             mc:Ignorable="d"
             x:Class="App1.MainPage">
    <StackLayout>
        <!-- Place new controls here -->
        <ios:UILabel Text="Hello World" TextColor="{x:Static ios:UIColor.Red}" View.HorizontalOptions="Start" />
        <androidWidget:TextView Text="Hello World" x:Arguments="{x:Static androidLocal:MainActivity.Instance}" />
    </StackLayout>
</ContentPage>

我在 MainPage.xaml.cs 文件中添加了跳过 Xamlcompliitation。

[XamlCompilation(XamlCompilationOptions.Skip)]

在 App1.Android 文件的 MainActivity.cs 中添加。

内部静态 MainActivity 实例 { get;私人套装; } // 定义实例

位显示错误

 ( 8976): Assembly Ref addref System.Xml[0xd1e768c0] -> System[0xe4b32b00]: 5
**Xamarin.Forms.Xaml.XamlParseException:** 'Position 15:52. Type MainActivity not found in xmlns clr-namespace:App1.Android;assembly=App1.Android;targetPlatform=Android'

【问题讨论】:

  • MainActivity 的命名空间是 App1.Droid,而不是 App1.Android
  • 我用这个替换它。我没有收到任何错误。但是当我运行项目时无法看到 Android 的标签。 xmlns:androidLocal="clr-namespace:App1.Droid;assembly=App1.Droid;targetPlatform=Android"

标签: xamarin xamarin.forms xamarin.android


【解决方案1】:
[XamlCompilation(XamlCompilationOptions.Skip)]

是您添加到 Xaml 后端代码中的内容。将其添加到您的案例中可能会导致问题。

【讨论】:

  • 我已将此添加到 App.xaml.cs 。我需要在 MainPage.xaml.cs 添加它。添加它和 .Droid 而不是 App1.Android 解决了我的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-12
  • 1970-01-01
  • 2018-04-29
  • 2020-06-26
  • 1970-01-01
  • 2021-09-16
相关资源
最近更新 更多