[英]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.