,所以我得到一個問題結合項目的ListView不能Xamarin窗體上綁定的ObservableCollection到的ListView
初始化頁面
public HomePage()
{
Acquaintances = Add();
//InitializeToolbar();
InitializeComponent();
}
private ObservableCollection<Acquaintance> Add()
{
return new ObservableCollection<Acquaintance>()
{
new Acquaintance(){.....}
在XAML
<ListView x:Name="lstUser" BackgroundColor="White" ItemsSource="{Binding Acquaintances}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<ImageCell ImageSource="{Binding PhotoUrl}" Height="50"></ImageCell>
</Grid>
<StackLayout Grid.Column="1" Padding="5">
<Label Text="{Binding FirstName}" FontSize="15" TextColor="Black"></Label>
<Label Text="{Binding City}" FontSize="10" TextColor="Black"></Label>
<Label Text="{Binding JobTitle}" FontSize="10" TextColor="#CCCCCC"></Label>
</StackLayout>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
ListView控件不能綁定熟人ListView的項目源。哪裏錯了?
在頁:
public ObservableCollection<Acquaintance> Acquaintances { get; }
你有沒有設置BindingContext? – Jason
是的,我試過了。 –
BindingContext =熟人; –