Unable to set properties for nested classes from Xaml

The error Xamarin returns is: Foo type not found in xmlns clr-namespace: AmsterdamTheMapV3

The problem is that I'm trying to determine Foo, but whatever I do, it works. I think the problem is inside the xmls: local namespace. Maybe I'm making a stupid mistake inside my code.

This is the Xamarin.forms project for windows, android and apple.

Xaml file:

<?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 file:

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));
        }
    }
}

I hope someone can help me.
If necessary, I can provide more information.
thanks in advance!

+4
source share
2 answers

Xaml.

google, . , Xaml Parsers Attached (Bindable | Dependency) .

Foo CityGuide , .

xmlns xmlns:local="clr-namespace:AmsterdamTheMapV3" assembly=, .

: fooobar.com/questions/178970/...

, + ( Reflection). , , +, xml- (https://www.xml.com/pub/a/2001/07/25/namingparts.html)

+9

.

xmlns:local="clr-namespace:AmsterdamTheMapV3; assembly=AmsterdamTheMapV3">

:

, PCL, AppConstants, XAML local. CLR (Common Language Runtime) ( .NET, , # using) , .

-1

Source: https://habr.com/ru/post/1658067/


All Articles