Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MAUI: Binding to my viewmodel throws an error before compilation (prop not found)

I have a simple view model:

public List<DisplayModel> Items { get; set; } = new List<DisplayModel>();

public class DisplayModel
{
    public string Name { get; set; }
    public string Prop { get; set; }   
}

In my view, I have this collection view:

<CollectionView ItemsSource="{Binding Items}" >
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <VerticalStackLayout>
                <Grid ColumnSpacing="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label TextColor="White" FontSize="18" FontFamily="WuerthExtraBold"  Text="{Binding Name}"/>
                    <Label TextColor="White" FontSize="18" FontAttributes="Bold"   Grid.Column="1" HorizontalTextAlignment="End" HorizontalOptions="End" Text="{Binding Prop}"/>
                </Grid>
            </VerticalStackLayout>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

but as soon as I hit compile, it tell me that the property name or prop arent found:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I can bind to that list, but just not with those properties. What is going on?

>Solution :

you need to add a DataType

<DataTemplate x:DataType="local:DisplayModel">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading