When I charge my App class is not recognized

Asked

Viewed 121 times

0

It says that Badeview does not exist in the current context in this line of sham.g.Cs

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

private global::Xamarin.Forms.BadgeView bdgDesvioFat;

How do we fix 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 shaman

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

EDIT1

After altering my page at Diego’s suggestion, you made that mistake

[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 statement of the page where I want to display the badge. You have more image to display. Not to get too big the post, I put only these since the rest is 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 rotate

EDIT3 error:

Type Imageresource not found in xmlns clr-namespace:Operacional

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 fix it?

  • On your Grid, you have improperly placed the namespace local and I’m not sure if the rest of the content is correct... I think it should be <Image x:Name="imgDesvioFat" Grid.Row="1" Grid.Column="0" Source="caixa-28.png" Aspect="AspectFill"> only. But the question is shifting the original focus and I do not believe that at this point is useful to the community.

1 answer

1


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

In XAML you declare the xmlns. In this case, on every page you will use the component BadgeView you will need to declare the namespace first. 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 that case, local was the name I chose to reference that namespace on that page.

The Xamarin.Forms developer guide is essential to know the resources and understand the behavior of the platform, I strongly recommend that you invest some time consuming the content there.

Specifically on that 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 classes local to the Shared application PCL, such as Appconstants, XAML programmers often use the prefix local.

Source: https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/xaml_markup_extensions/


In a free translation made by me:

You will certainly need additional XML namespace 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 XAML code posted has some confusion and does not seem according to the creation of the component BadgeView presented in the question. Of share with the creation code of the BadgeView, You should declare in XAML like this:

<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 -->
  • I made an edit to indicate the error I’m picking up

  • @pnet that is not an error message. That is the code C# generated from XAML, possibly from the point where the error is being made. I need to know what the error message is. Note that the namespace that is stated there is Operacional.ViewModels.BadgeView instead of Operacional.BadgeView as I suggested (according to your component code).

  • I made another edition, just to show you how my code is. I’m reading the link about xaml that you posted.

  • @pnet, I guess you didn’t understand. I included in the answer what should be correct for the case you showed in the question. Just copy and paste, but the reading is valid. I think you’re missing some concepts. Let me know if it worked.

  • Diego, I have a disability in understanding the header of the shaman, which is why I’m reading a lot and trying to understand the past link. When I put xmlns:local="clr-namespace:Estapar.AppOperacional", for example, because it did not recognise the components in the Viewmodel.

  • From what I understand, I should put the Badgeview class inside the folder where I have Resourceimage(Viewmodel) and declare in the header of my shaman, right?

  • About xaml: https://www.wintellectnow.com/Videos/Watch?videoId=xaml-fundamentals

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.