【发布时间】:2016-08-13 07:18:56
【问题描述】:
在我的 Xamarin Forms 应用程序中,我试图在我的一个 xaml 文件中设置嵌入式图像的源,但是在创建自定义命名空间时出现错误
Xamarin.Forms.Xaml.XamlParseException: Position 31:12. MarkupExtension not found for local:ImageResource。我基于https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Embedded_Images 的官方文档,并且还检查了示例代码。我的程序集名称和默认命名空间都与 xaml 文件中的名称匹配。
我在 Windows 上使用 Visual Studio 2015。我让其他人在 Mac 上的 Xamarin Studio 上尝试了代码,代码运行良好并且图像显示。
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:local="clr-namespace:App;assembly=App"
x:Class="App.LoginPage">
<RelativeLayout>
<Label Text="Logo"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.3}" BackgroundColor="Aqua" />
<StackLayout Spacing="20" Padding="20"
VerticalOptions="Center"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"
RelativeLayout.XConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}"
RelativeLayout.YConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.3}">
<Entry Placeholder="Username"
Text="{Binding Username}"/>
<Entry Placeholder="Password"
Text="{Binding Password}"
IsPassword="true"/>
<Button Text="Login" TextColor="White"
BackgroundColor="Blue"
Command="{Binding LoginCommand}"/>
</StackLayout>
<Image Source="{local:ImageResource App.logo.png}"
Aspect="AspectFill"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.4}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.15}"
RelativeLayout.XConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.6}"
RelativeLayout.YConstraint= "{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.85}" />
</RelativeLayout>
</ContentPage>
谁能帮忙?
【问题讨论】:
-
您在构建或运行项目时是否收到此错误?
标签: xamarin.forms