我正在使用 VS 2019 最新版本创建一个 Xamarin Forms 移动应用程序。Xamarin Forms 和 Essentials 包也更新到最新版本。我有以下视图模型,但未通过调用 LoadHouses() 方法
24. LoadHousesCommand = new AsyncCommand(LoadHouses);
知道为什么吗?我还收到“当前不会命中断点”警告。谢谢
编辑: 我的 xaml 页面如下,
<?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="HomeInventory.Views.HousesPage"
xmlns:viewmodels="clr-namespace:HomeInventory.ViewModels"
xmlns:models="clr-namespace:Shared.Models;assembly=Shared"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
x:DataType="viewmodels:HouseViewModel"
>
<ContentPage.BindingContext>
<viewmodels:HouseViewModel />
</ContentPage.BindingContext>
<ContentPage.Content>
<ListView ItemsSource="{Binding Houses}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:House">
<TextCell Text="{Binding Name}"></TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
当我在构造函数中手动添加房屋时,它工作正常,
public HouseViewModel()
{
Houses = new ObservableRangeCollection<House>();
LoadHousesCommand = new AsyncCommand(LoadHouses);
House h1 = new House();
h1.Name = "House 01";
Houses.Add(h1);
House h2 = new House();
h2.Name = "House 02";
Houses.Add(h2);
}