Xamarin报错:在xmlns clr-namespace:AmsterdamTheMapV3中未找到类型Foo。
问题在于我尝试定义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));
}
}
}
希望有人能够帮助我。
如需更多信息请告知。
提前感谢您!
Label
和一个ScrollView
,但是ContentPage
只接受单个属性作为Content
。在编写时,Xamarin.Forms Xaml解析器非常宽容,其中一个项目被忽略(通常是除最后一个之外的所有项目),但这可能会在未来发生变化并抛出异常。 - Stephane Delcroix