我解决了你的问题。我所做的是,我将 ListPicker Itemsource 绑定在 .xaml 而不是后面的代码上,它运行良好。
这是在您提供的文件中编辑的 .xaml 代码:
<toolkit:ListPicker ItemsSource="{Binding LstCountry}" SelectedIndex="55" x:Name="listPickerCountrySignup" Height="72" HorizontalAlignment="Left" Margin="14,43,0,0" VerticalAlignment="Top" Width="436" FullModeHeader="Select Country" Background="White" BorderBrush="White" CacheMode="BitmapCache" >
.xaml.cs 代码
public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged { // 构造函数 public MainPage() { InitializeComponent(); 绑定列表();this.DataContext=这个;}
public class country
{
public int CountryID { get; set; }
}
public event PropertyChangedEventHandler PropertyChanged;
void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
List<country> _lstCountry;
public List<country> LstCountry
{
get{return _lstCountry;}
set{
if(_lstCountry!=value)
{
_lstCountry = value;
NotifyPropertyChanged("LstCountry");
}
}
}
void BindList()
{
LstCountry = new List<country>();
for (int i = 0; i <= 100; i++)
{
LstCountry.Add(new country { CountryID = i });
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
listPickerCountrySignup.SelectedIndex = 15;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
listPickerCountrySignup.SelectedIndex = 25;
}
private void button3_Click(object sender, RoutedEventArgs e)
{
listPickerCountrySignup.SelectedIndex = 39;
}
private void button4_Click(object sender, RoutedEventArgs e)
{
listPickerCountrySignup.SelectedIndex = 55;
}
private void button5_Click(object sender, RoutedEventArgs e)
{
listPickerCountrySignup.SelectedIndex = 75;
}
}