简体   繁体   中英

Listpicker goes blank after setting setting selected index

I have listpicker control in my wp7 app. And I want To Set Selected Index as per my needs. Lets Suppose I Have 100 items in my listpicker If I Set The selected index below 40 it goes well. But When I set Selected index above 50 it goes blank and UI not refreshed but on backend it shows correct item.

Sample Project : http://yaariyan.net/Test_Project.rar

In this project you can get

  1. All Source

  2. XAP file to test as well

  3. Steps To Reproduce

  4. Snapshot of Error

Just Play with my last two button you can easily reproduce issue.

I am using windows phone 7.1.1 SDK And Silverlight Took Kit November 2011 Version.

DLL is also in my folder That I am referring in my project

I have experienced the same issue. I'm afraid I can't come up with a solution yet, but I have narrowed down the problem a bit. I can verify that the problem seems to occur somewhere between SelectedIndex 40 and 50 (48 in my case).

What I did to narrow it down was to simply create a new WP solution, add two ListPicker controls to the MainPage.xaml view, plus a button. I add 50 strings to both lists through code and set the SelectedIndex to 0 on the first list and 50 on the second one.

The button does a simple switch of the SelectedIndex properties like this:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        int tempindex = listPicker1.SelectedIndex;
        listPicker1.SelectedIndex = listPicker2.SelectedIndex;
        listPicker2.SelectedIndex = tempindex;
    }

I ran the project and ended up with this (the movie says it all, I think):

http://screencast.com/t/T6mZ7FEdUF

I solved your problem. What I did was, I binded the ListPicker Itemsource on the .xaml and not on the code behind and it worked perfectly.

this is the .xaml code edited in the file provided by you:

        <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 code

public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged { // Constructor 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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM