简体   繁体   English

设置设置选定的索引后,列表选择器变为空白

[英]Listpicker goes blank after setting setting selected index

I have listpicker control in my wp7 app. 我的wp7应用程序中有listpicker控件。 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. 假设我的列表选择器中有100个项目如果我将所选索引设置为40以下,则效果很好。 But When I set Selected index above 50 it goes blank and UI not refreshed but on backend it shows correct item. 但是,当我将Selected index设置为50以上时,它将变为空白,UI不会刷新,但在后端显示正确的项目。

Sample Project : http://yaariyan.net/Test_Project.rar 示例项目:http: //yaariyan.net/Test_Project.rar

In this project you can get 在这个项目中,您可以获得

  1. All Source 全部来源

  2. XAP file to test as well XAP文件也要测试

  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. 我正在使用Windows Phone 7.1.1 SDK和Silverlight Took Kit 2011年11月版。

DLL is also in my folder That I am referring in my project DLL也位于我在项目中引用的文件夹中

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). 我可以验证问题似乎发生在SelectedIndex 40和50之间(在我的情况下为48)。

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. 我要做的只是简单地创建一个新的WP解决方案,在MainPage.xaml视图中添加两个ListPicker控件,以及一个按钮。 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. 我通过代码将50个字符串添加到两个列表中,然后在第一个列表上将SelectedIndex设置为0,在第二个列表上将其设置为50。

The button does a simple switch of the SelectedIndex properties like this: 该按钮对SelectedIndex属性进行简单的切换,如下所示:

    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 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. 我所做的是,我将ListPicker Itemsource绑定到了.xaml而不是其背后的代码上,并且运行良好。

this is the .xaml code edited in the file provided by you: 这是在您提供的文件中编辑的.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 code .xaml.cs代码

public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged { // Constructor public MainPage() { InitializeComponent(); 公共部分类MainPage:PhoneApplicationPage,INotifyPropertyChanged {//构造方法public MainPage(){InitializeComponent(); BindList(); BindList(); this.DataContext= this; 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.

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