Xamarin VS2022 Member Not Found In DataContext Only At Compile Time

- 1 answer

(Note I am commenting out everything inside the starting from <!--<ListView.ItemTemplate>)

If I take out the comment block and try to run the code I get the compiler error "

Member not found in DataContext XFC0045 Binding: Property "SyllabusNumber" not found on "ViewModels.FlightViewModel"

Note: Not just SyllabusNumber, any field will fail but it only catches on the first.

If I run it with the code commented out the app will start and show me a list of object.tostring() text items "models.LessonModel". While the app is running I then un-comment the code and use the Hot Reload and everything is working fine.

The window's DataContext is set to the ViewModel and Lessons is a public ObservableCollection in the VM. All other bindings to the VM are working fine and as expected. I have set all access modifiers to 'public'. I have tried it in VS2022 and VS2022 Preview.

                    <ListView  x:Name="listView" ItemsSource="{Binding Lessons}" Margin="30" >
                                    <StackLayout BackgroundColor="#eee" Orientation="Horizontal">
                                        --><!-- <Image Source="{Binding image}" />  --><!--

                                        <StackLayout Orientation="Vertical">
                                            <StackLayout Orientation="Horizontal">
                                                <Label Text="{Binding SyllabusNumber}" TextColor="#ddd" BackgroundColor="#333" Padding="5,0,5,0"/>
                                                <Label Text="{Binding Name}" TextColor="#333" />
                                            <Label Text="{Binding Description}" TextColor="#666" />


remove the x:DataType attribute from the XAML. For some reason doing this for the overall page creates problems with templated controls that have their own context.