データバインディングを使用してxamarinフォームで単純なリストアプリケーションを作成しようとしていますが、データが表示されません。 は、ここに私のMainPage.xamlをXamarin ListViewが表示されない
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Practice3"
x:Class="Practice3.MainPage">
<StackLayout>
<ListView ItemsSource="{Binding Films}">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
Text="{Binding Title}"
TextColor="Black"
Detail="{Binding Resume}"
DetailColor="Gray"
/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
は、ここで私はちょうどStackLayoutにラベルを入れてみました、それは登場MainPage.xaml.cs
namespace Practice3
{
public partial class MainPage : ContentPage
{
public ObservableCollection<Film> Films { get; set; }
public MainPage()
{
InitializeComponent();
Films = new ObservableCollection<Film>{
new Film{
Title = "X-Men (2000)",
Resume = "Two mutants come to a private academy for their kind whose resident superhero team must oppose a terrorist organization with similar powers."
},
new Film{
Title = "X-Men 2 (2003)",
Resume = "The X-Men band together to find a mutant assassin who has made an attempt on the President's life, while the Mutant Academy is attacked by military forces."
},
new Film{
Title = "X-Men: The last stand (2006)",
Resume = "When a cure is found to treat mutations, lines are drawn amongst the X-Men, led by Professor Charles Xavier, and the Brotherhood, a band of powerful mutants organized under Xavier's former ally, Magneto."
}
};
}
}
}
そしてFilms.cs
namespace Practice3
{
public class Film
{
public string Title { get; set; }
public string Resume { get; set; }
}
}
だです明らかに、ListViewは空または不可視であるようです。
あなたはINPCを実装するのですか?別のMainPageViewModel.csを作成する必要があります。 –
BindingContextを設定する必要があります:this.BindingContext = this; – Jason
@Jasonそれは暗黙のうちではない? –