【发布时间】:2016-10-18 08:44:53
【问题描述】:
Xamarin 返回的错误:Type Foo not found in xmlns clr-namespace:AmsterdamTheMapV3
问题是我正在尝试定义 Foo 但无论我做什么它都不起作用。我认为问题出在 xmls:local 命名空间内。也许我在代码中犯了一个愚蠢的错误。
这是一个适用于 windows、android 和 apple 的 Xamarin.forms 项目。
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"
x:Class="AmsterdamTheMapV3.CityGuide"
xmlns:local="clr-namespace:AmsterdamTheMapV3">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<ScrollView Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Spacing="0">
<!-- Button1 -->
<Image
x:Name="CityGuideButton1"
Source="shopping_gray.png"
Aspect="Fill"
HorizontalOptions="FillAndExpand"
VerticalOptions ="FillAndExpand"
local:Foo.Tag="button1">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="Categorie_Onclick"
NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
</ScrollView>
</ContentPage>
cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace AmsterdamTheMapV3
{
public partial class CityGuide : ContentPage
{
public CityGuide()
{
InitializeComponent();
}
public class Foo
{
public static readonly BindableProperty TagProperty = BindableProperty.Create("Tag", typeof(string), typeof(Foo), null);
public static string GetTag(BindableObject bindable)
{
return (string)bindable.GetValue(TagProperty);
}
public static void SetTag(BindableObject bindable, string value)
{
bindable.SetValue(TagProperty, value);
}
}
async void Categorie_Onclick(Object sender, EventArgs args)
{
Image cmd = sender as Image;
string txt = Foo.GetTag(cmd);
await Navigation.PushAsync(new CategoriePage(txt));
}
}
}
我希望有人能帮助我。
如果需要,我可以提供更多信息。
提前谢谢你!
【问题讨论】:
-
请注意,您的 Xaml 可能不会显示您所期望的内容。您的 contentPage 有 2 个孩子,一个
Label和一个ScrollView,但ContentPage只接受一个属性为Content。在撰写本文时,Xamarin.Forms Xaml 解析器非常宽容,忽略了 2 项中的一项(通常除了最后一项),但将来可能会改变并抛出。 -
我在上传此问题后确实更改了它。标签不应该在那里。但仍然感谢您的反馈。我会记住这一点。
标签: c# android xaml xamarin xamarin.forms