When I load my App class is not recognized

0

It says that BadeView does not exist in the current context in this line of xaml.g.cs

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")] 

private global::Xamarin.Forms.BadgeView bdgDesvioFat;

How to solve this? My BadgeView

<?xml version="1.0" encoding="utf-8" ?>
<Grid      
    xmlns="http://xamarin.com/schemas/2014/forms"      
    xmlns:local="clr-namespace:Operacional"     
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"     
    x:Class="Operacional.BadgeView"     
        HeightRequest="16"     
        WidthRequest="16">

    <local:CircleView x:Name="BadgeCircle" 
                      HeightRequest="16" 
                      WidthRequest="16" 
                      CornerRadius="16" 
                      VerticalOptions="Center" 
                      HorizontalOptions="Center" />

    <Label x:Name="BadgeLabel" 
           TextColor="White" 
           VerticalOptions="Center" 
           HorizontalOptions="Center" 
           VerticalTextAlignment="Center" 
           HorizontalTextAlignment="Center" 
           FontSize="10"/>
</Grid>

and here I call the BadgeView inside the xaml

<BadgeView Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"
                    x:Name="bdgDesvioFat"
                    BadgeColor="Blue"/>

EDIT1

After changing my page with Diego's suggestion, he started giving this error

  

[global :: System.CodeDom.Compiler.GeneratedCodeAttribute ("Xamarin.Forms.Build.Tasks.XamlG",   "0.0.0.0")]           private global :: Operational.ViewModels.BadgeView bdgDesvioFat;

EDIT2

This is the xaml declaration of the page where I want to display the badge. You have more image to display. In order not to get too big the post, I put only those ones since the others are all similar.

<?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="Operacional.Views.Indicadores"
             xmlns:local="clr-namespace:Operacional.ViewModels"
             xmlns:badge="clr-namespace:Operacional.BadgeView.Shared;assembly=BadgeView.Shared"
             Title="[email protected]"             
             Icon="person.png"
             >
<ContentPage.Content>
        <StackLayout Padding="0" Spacing="0" Margin="0">

            <local:BadgeView x:Name="bdgDesvioFat"
                        BadgeColor="Blue"/>

            <Grid x:Name="grd" RowSpacing="1" ColumnSpacing="1" Padding="0" Margin="0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="1" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

                <Image x:Name="imgDesvioFat" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Source="{local:ImageResource Operacional.Images.faturamento caixa-28.png}" Aspect="AspectFill">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnDesvioFaturamentoTapReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
                        </Image.GestureRecognizers>
                    </Image>
                <!--<Label x:Name="lblFaturamento" Text="" Grid.Row="0" Grid.Column="0" TextColor="White" FontSize="9" FontAttributes="Bold" />-->    

                <!--</Grid>-->
                <Image x:Name="imgTckCancelados" Grid.Row="1" Grid.Column="1" Source="{local:ImageResource Operacinal.Images.tickets cancelados-05.png}" Aspect="AspectFill">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnTckCanceladosTapGestureReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
                    </Image.GestureRecognizers>
                </Image>

What can I do to improve this and run

EDIT3 error:

  

Type ImageResource not found in xmlns clr-namespace: Operational

I did this, following the tip of colleague Diego

<?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="Operacional.Views.Indicadores"
             xmlns:local="clr-namespace:Operacional"
             Title="[email protected]"             
             Icon="person.png"
             >

    <ContentPage.Content>
        <StackLayout Padding="0" Spacing="0" Margin="0">

            <local:BadgeView x:Name="bdgDesvioFat"
                        BadgeColor="Blue"/>

            <Grid x:Name="grd" RowSpacing="1" ColumnSpacing="1" Padding="0" Margin="0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="1" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

                <Image x:Name="imgDesvioFat" Grid.Row="1" Grid.Column="0" Source="{local:ImageResource Operacional.Images.faturamento caixa-28.png}" Aspect="AspectFill">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnDesvioFaturamentoTapReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
                        </Image.GestureRecognizers>
                    </Image>

How do I resolve this?

    
asked by anonymous 23.02.2018 / 21:23

1 answer

1

In the class where you use a component that is not from the Xamarin.Forms platform itself, you need to first import the namespace in XAML, similarly to what you do in C# ( using MeuProjeto.Views.Badge; ).

In XAML you declare xmlns . In this case, on every page you will use the BadgeView component you will need to declare the namespace before. For example, like this:

<?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:Operacional"
             x:Class="App.Views.MyPage">
    <StackLayout>
        <!-- Aqui vai o conteúdo da sua página-->
        <local:BadgeView x:Name="bdgDesvioFat"
                        BadgeColor="Blue"/>
    </StackLayout>
</ContentPage>

In this case, local was the name I chose to refer to that namespace on that page.

The Xamarin.Forms Developer Guide is essential for understanding resources and understanding the behavior of the platform, strongly recommend that you invest time consuming content from there.

Specifically on this subject, it says:

  

You'll need additional XML namespace declarations to access other classes. Each additional XML namespace declaration defines a new prefix. To access local classes to the shared PCL application, such as AppConstants, XAML programmers often use the local prefix.

Source: link

In a free translation made by me:

  

You will certainly need additional XML namespaces declarations to access other classes. Each additional namespace defines a new prefix. To use local application classes developers usually use the prefix local

Issue 1

The posted XAML code has some confusion and does not seem to agree with the creation of the BadgeView component presented in the question. In line with the BadgeView creation code, you should declare in XAML as follows:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Operacional.Views.Indicadores"
             xmlns:local="clr-namespace:Operacional"
             Title="[email protected]"             
             Icon="person.png"
             >
<ContentPage.Content>
        <StackLayout Padding="0" Spacing="0" Margin="0">
            <local:BadgeView x:Name="bdgDesvioFat"
                        BadgeColor="Blue"/>
<!-- ... Todo o resto do seu código -->
    
23.02.2018 / 22:07