【问题标题】:Bad XAML still compiles with no error, then runtime error occurs in Xamarin.Forms project错误的 XAML 仍然编译没有错误,然后在 Xamarin.Forms 项目中发生运行时错误
【发布时间】:2018-03-02 11:45:40
【问题描述】:

上下文

在我的所有项目(包括一个新创建的项目)中,我可以在我的 XAML 中打错字,然后编译没有错误,没有警告。 当然运行时会抛出异常。

问题

这是正常的还是我的 Visual Studio 2017.3 出了问题?

【问题讨论】:

  • 请查看this page in the Microsoft documentation。如果您在 XAML 中使用绑定,请不要忘记通过指定 x:DataType 来设置绑定上下文的类型,否则绑定的编译将(或多或少)静默失败。

标签: c# visual-studio xaml xamarin xamarin.forms


【解决方案1】:

在为Xamarin.FormsWPFXaml 时这是正常的

Xamarin 确实带来的一个好处是 Xaml Compliation

XAML 可以选择直接编译成中间语言 (IL) 与 XAML 编译器 (XAMLC)。

XAMLC 提供了许多好处:

  • 它执行 XAML 的编译时检查,通知用户任何 错误。

  • 它消除了 XAML 的一些加载和实例化时间 元素。

  • 它有助于减少最终程序集的文件大小 更长,包括 .xaml 文件。

注意这里的第一个要点:

  • 它执行 XAML 的编译时检查,通知用户任何 错误。

要使用它,请执行以下操作:

以下代码示例演示了在程序集级别启用 XAMLC:

using Xamarin.Forms.Xaml;
...
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace PhotoApp
{
   ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多