Xaml doesn't see the namespace

Kobi 26 Reputation points
2021-02-24T13:55:34.41+00:00

Hi,

I have error

Views\RouteList.xaml(101,40): XamlC error XFC0045: Binding: Property "RouteStatusName" not found on "Models.Responses.GetRouteListResponseBase".

This error is after I add new properties to model and try binding this prop. My Model is in another assembly:

namespace Models.Responses
{
    public class GetRouteListResponseBase
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime PlannedDate { get; set; }
        public double Distance { get; set; }
        public RouteStatus RouteStatus { get; set; }
        public string RouteStatusName { get; set; }

        [JsonIgnore]
        public bool Today => PlannedDate == DateTime.Today;

        [JsonIgnore]
        public bool Late
        {
            get
            {
                return PlannedDate < DateTime.Today;
            }
        }

        [JsonIgnore]
        public bool Future
        {
            get
            {
                return PlannedDate > DateTime.Today;
            }
        }
    }
}

And here is my XAML. What I do wrong?

<?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="nMscoutApp.Views.RouteList"
             xmlns:response="clr-namespace:Models.Responses;assembly=Models" 
             xmlns:vm="clr-namespace:nMscoutApp.ViewModels"
             Title="{Binding Title}">

    <ContentPage.BindingContext>
        <vm:RouteListViewModel />
    </ContentPage.BindingContext>

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Odśwież" Command="{Binding RefreshCommand}" />
    </ContentPage.ToolbarItems>

    <StackLayout>

        <RefreshView x:DataType="local:RouteListViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
            <ListView x:Name="listView" CachingStrategy="RecycleElement"
                  ItemsSource="{Binding Routes}"
                  Grid.Row="2"
                  HasUnevenRows="true"
                  SeparatorVisibility="None">
                <ListView.Resources>
                    <Style TargetType="{x:Type Frame}">
                        <Style.Triggers>
                            <DataTrigger TargetType="{x:Type Frame}"
                                     Binding="{Binding Late}"
                                     Value="true">
                                <Setter Property="Background"
                                    Value="LightGray"/>
                            </DataTrigger>
                            <DataTrigger TargetType="{x:Type Frame}"
                                     Binding="{Binding Future}"
                                     Value="true">
                                <Setter Property="Background"
                                    Value="LightGreen"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Resources>
                <!--<ListView.Behaviors>
                <b:EventToCommandBehavior EventName="ItemTapped"
                                          Command="{Binding OnItemTappedCommand}"
                                          EventArgsConverter="{converters:ItemTappedEventArgsConverter}"/>
            </ListView.Behaviors>-->
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell x:DataType="response:GetRouteListResponseBase">
                            <Frame BorderColor="White" Margin="10">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20"></RowDefinition>
                                        <RowDefinition Height="20"></RowDefinition>
                                        <RowDefinition Height="20"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                        <ColumnDefinition Width="120"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>

                                    <Label Grid.RowSpan="2" 
                                       Grid.Row="0" 
                                       Grid.Column="0" 
                                       Text="{Binding Name}" 
                                       FontSize="Large"  
                                       LineBreakMode="TailTruncation"/>
                                    <Label VerticalTextAlignment="Center"
                                       HorizontalTextAlignment="End"
                                       Grid.Row="0" Grid.Column="1"
                                       Text="{Binding PlannedDate, StringFormat='{0:dd-MM-yyyy}'}"
                                       FontSize="Medium"
                                       TextColor="Gray"
                                       LineBreakMode="TailTruncation"/>
                                    <Label VerticalTextAlignment="Center"
                                       HorizontalTextAlignment="End"
                                       Grid.Row="1" Grid.Column="1"
                                       Text="{Binding Distance, StringFormat='{0:N} km'}"
                                       FontSize="Medium"
                                       TextColor="Gray"
                                       LineBreakMode="TailTruncation"/>
                                    <Label VerticalTextAlignment="Center"
                                       HorizontalTextAlignment="Start"
                                       Grid.Row="2"
                                       Grid.Column="0"
                                       Text="{Binding RouteStatusName}"
                                       FontSize="Medium"
                                       TextColor="Gray"
                                       LineBreakMode="TailTruncation"/>
                                </Grid>
                            </Frame>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </RefreshView>
    </StackLayout>
</ContentPage>

Error is with last Label (Text="{Binding RouteStatusName}").

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,272 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Michael Taylor 45,986 Reputation points
    2021-02-24T14:38:35.963+00:00

    Is this the only error you are getting or are there others as well?
    Did you close and reopen the designer to see if the issue goes away?
    Are you sure that the UI project is referencing the project Models and not the assembly with the same name (check the project's references)?

    1 person found this answer helpful.

  2. Ricardo Melara 1 Reputation point
    2021-05-31T15:12:27.06+00:00

    I have the same problem :(
    1>Views\GroupDetailListPage.xaml(23,36): XamlC error XFC0045: Binding: Property "Name" not found on "GeneralUI.ViewModels.GroupDetailListPageViewModel"

    Did you resolve?

    0 comments No comments