![](/img/trans.png)
[英]What is the way to include styles from other XAML file using Xamarin Forms latest update
[英]Xamarin Forms include xaml file
我有一个写标题的 xaml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<ContentView 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"
mc:Ignorable="d"
x:Class="TeenageClubWallet.Templates.Header">
<StackLayout>
<Label Text="Header!" />
</StackLayout>
我想将此 xaml 文件用作其他 xaml 文件中的标头。 这是一个例子。 我正在尝试将它包含到另一个 xaml 文件中:
我添加了一个命名空间:xmlns:template="clr-namespace:TeenageClubWallet.Templates"
“模板”标签现在用于包含文件:
<?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"
mc:Ignorable="d"
x:Class="TeenageClubWallet.Statistics"
xmlns:template="clr-namespace:TeenageClubWallet.Templates">
<ContentPage.Content>
<template:Header/>
<StackLayout>
<Label Text="Content!" />
</StackLayout>
</ContentPage.Content>
Visual Studio 显示错误:“错误 XLS0501 多次设置属性‘内容’。”
如何将一个 xaml 文件中的内容包含到另一个 xaml 文件中?
在此示例中ContentPage
有两个元素 - template:Header
和StackLayout
并且只允许使用一个。
这就是这个问题的原因。 我没有更深入地评估是否还有其他问题,但是如果它们存在并且您无法解决它们,您应该提出一个新问题。
我修好了它
要解决此问题,您需要在<StackLayout>
标签内插入<template:Header/>
<StackLayout>
标签。
下面是完整的代码:
<?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" mc:Ignorable="d" x:Class="TeenageClubWallet.Statistics" xmlns:template="clr-namespace:TeenageClubWallet.Templates"> <ContentPage.Content> <StackLayout> <template:Header/> <Label Text="Content!" /> </StackLayout> </ContentPage.Content>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.