1

当我在Windows Phone 8 SDK.

枢轴绑定到一个名为的列表Students并在单击它时设置一个按钮,将新建一个新的学生对象并将其设置Students[2]为新值。这导致了下面屏幕截图中显示的重叠问题。有没有其他人遇到过这个问题WP8 SDK

这是代码

  public MainPage()
    {
        InitializeComponent();
        this.DataContext = this;

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
        InitiList();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        int index = 2;
        Students[index] = new Student();
        Students[index].Name = "tian";
        Students[index].College = "shida";
    }

    private ObservableCollection<Student> _students;
    public ObservableCollection<Student> Students
    {
        get { return _students; }
        set
        {
            _students = value;
            RaisePropertyChanged("Students");
        }
    }

    private void InitiList()
    {
        Students = new ObservableCollection<Student>();
        Students.Add(new Student { Name="a",College="aa"});
        Students.Add(new Student { Name = "b", College = "aa" });
        Students.Add(new Student { Name = "c", College = "aa" });
        Students.Add(new Student { Name = "d", College = "aa" });
        Students.Add(new Student { Name = "e", College = "aa" });
    }

检查这个 o/p 图像:

在此处输入图像描述

4

2 回答 2

0

您正在修改学生,但 RaisePropertyChanged 没有被解雇,因为访问学生不会触发 Set,它调用 RaisePropertyChanged。这可能是问题所在,我现在无法测试。

于 2012-11-06T03:35:52.003 回答
0

我遇到了同样的问题,我通过将项目添加到构造函数中的 ObservableCollection 而不是使用 Add 方法来修复它。这似乎是 ObservableCollection 类的一个错误。尝试将您的代码更改为:

 private void InitiList()
{
    Students = new ObservableCollection<Student>(new [] {
    new Student { Name="a",College="aa"}),
    new Student { Name = "b", College = "aa" }),
    new Student { Name = "c", College = "aa" }),
    new Student { Name = "d", College = "aa" }),
    new Student { Name = "e", College = "aa" })
    });
}
于 2013-01-21T05:37:48.407 回答