在我的Windows Phone 8.1商店应用中,我无法在LongListSelector中显示值。这是.xaml和.cs文件。
我错过了什么吗?
<controls:LongListSelector Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch"
DataContext="{Binding ElementName=PageWorld}"
ItemsSource="{Binding Countries}" RenderTransformOrigin="0.5,0.5" BorderBrush="Blue" BorderThickness="2">
<controls:LongListSelector.RenderTransform>
<CompositeTransform/>
</controls:LongListSelector.RenderTransform>
<controls:LongListSelector.ItemTemplate>
<DataTemplate>
<ListBoxItem Margin="0,6,0,6">
<StackPanel>
<TextBlock Text="{Binding Title}" TextWrapping="NoWrap" Foreground="Black"/>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</controls:LongListSelector.ItemTemplate>
</controls:LongListSelector>
在代码behing中,我的绑定值如下所示。
private ObservableCollection<Country> _countries;
public ObservableCollection<Country> Countries
{
get { return _countries; }
set
{
_countries = value;
OnPropertyChanged();
}
}
public World()
{
InitializeComponent();
navigationHelper = new NavigationHelper(this);
navigationHelper.LoadState += this.NavigationHelper_LoadState;
navigationHelper.SaveState += this.NavigationHelper_SaveState;
Countries = GetCountries();
}
public class Country
{
public string Title { get; set; }
}
private ObservableCollection<Country> GetCountries()
{
ObservableCollection<Country> countries = new ObservableCollection<Country>();
for (int i = 0; i < 100; i++)
{
Country country = new Country();
country.Title = "Name" + i;
countries.Add(country);
}
return countries;
}