Xamarin XLS0502:类型 'Thickness' 不支持直接内容

Xamarin XLS0502: The type 'Thickness' does not support direct content

我刚刚在 VS2019 中启动了一个新的 Xamarin(Android & iOS)项目,并且一直在关注 this quick start guide 构建示例应用程序。

它要求您添加到 App.xaml 的其中一行是

<Thickness x:Key="PageMargin">20</Thickness>

但是,IntelliSense 会立即在其下划线显示上述错误(错误,而非警告)。它仍然以某种方式构建(我认为错误应该阻止构建?)并按预期工作,所以错误的错误消息让我感到困惑。

我使用的是过时的解析器吗?我已经检查过所有 Xamarin Nuget 包都是最新的,并且如前所述,我使用的是 Visual Studio 2019,所以我不明白为什么会出现这个问题。

或者是否有更现代的写法?该教程只有几个月的历史...

你正在尝试定义一个资源,你也可以这样写:

<Thickness x:Key="PageMargin" Left="20" Top="20" Right="20" Bottom="20"/>
    <Thickness x:Key="PageMargin"  >
        <Thickness.Bottom>20</Thickness.Bottom>
    </Thickness>