更改绑定源时WP8 Pivot重叠

时间:2012-11-05 10:07:00

标签: pivot windows-phone-8

我在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" });
    }

Ckeck this o / p image:

enter image description here

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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" })
    });
}
相关问题