1

我的 wp7 应用程序中有 listpicker 控件。我想根据我的需要设置选定的索引。假设我的列表选择器中有 100 个项目,如果我将选定的索引设置为 40 以下,则一切顺利。但是当我将 Selected index 设置为 50 以上时,它变为空白并且 UI 未刷新,但在后端它显示正确的项目。

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

在这个项目中你可以获得

  1. 所有来源

  2. XAP 文件也进行测试

  3. 重现步骤

  4. 错误快照

只需使用我的最后两个按钮即可轻松重现问题。

我正在使用 windows phone 7.1.1 SDK 和 Silverlight Take Kit 2011 年 11 月版。

DLL 也在我的文件夹中,我在我的项目中指的是

4

2 回答 2

0

我遇到过同样的问题。恐怕我还不能提出解决方案,但我已经缩小了问题的范围。我可以验证问题似乎发生在SelectedIndex40 到 50 之间(在我的情况下为 48)。

我所做的缩小范围是简单地创建一个新的 WP 解决方案,ListPicker向视图添加两个控件MainPage.xaml,以及一个按钮。我通过代码将 50 个字符串添加到两个列表中,并在第一个列表上设置SelectedIndex为 0,在第二个列表上设置为 50。

该按钮对 SelectedIndex 属性进行了简单的切换,如下所示:

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

我运行了这个项目并最终完成了这个(我认为这部电影说明了一切):

http://screencast.com/t/T6mZ7FEdUF

于 2012-08-17T18:39:06.510 回答
0

我解决了你的问题。我所做的是,我将 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;
    }
}
于 2012-08-21T02:56:18.103 回答