[英]Listpicker goes blank after setting setting selected index
我的wp7应用程序中有listpicker控件。 我想根据自己的需要设置选定的索引。 假设我的列表选择器中有100个项目如果我将所选索引设置为40以下,则效果很好。 但是,当我将Selected index设置为50以上时,它将变为空白,UI不会刷新,但在后端显示正确的项目。
示例项目:http: //yaariyan.net/Test_Project.rar
在这个项目中,您可以获得
全部来源
XAP文件也要测试
重现步骤
错误快照
只需按一下我的最后两个按钮,即可轻松重现问题。
我正在使用Windows Phone 7.1.1 SDK和Silverlight Took Kit 2011年11月版。
DLL也位于我在项目中引用的文件夹中
我也遇到过同样的问题。 恐怕我还无法提出解决方案,但是我已经将问题缩小了一点。 我可以验证问题似乎发生在SelectedIndex
40和50之间(在我的情况下为48)。
我要做的只是简单地创建一个新的WP解决方案,在MainPage.xaml
视图中添加两个ListPicker
控件,以及一个按钮。 我通过代码将50个字符串添加到两个列表中,然后在第一个列表上将SelectedIndex
设置为0,在第二个列表上将其设置为50。
该按钮对SelectedIndex属性进行简单的切换,如下所示:
private void button1_Click(object sender, RoutedEventArgs e)
{
int tempindex = listPicker1.SelectedIndex;
listPicker1.SelectedIndex = listPicker2.SelectedIndex;
listPicker2.SelectedIndex = tempindex;
}
我运行了这个项目,并最终完成了这个工作(我想这部电影就说明了一切):
我解决了你的问题。 我所做的是,我将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代码
公共部分类MainPage:PhoneApplicationPage,INotifyPropertyChanged {//构造方法public MainPage(){InitializeComponent(); BindList(); this.DataContext = this; }
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.