uwpuwp-xaml

Grid ReOrder does not update items not moved


I have a very simple project. One grid mapped to an observable collection (for instance <int, string>. I added can reorder, candrop, candrag.

The object is moved fine but only the moved object gets updated even after calling an event on obscollection changed (although binding is defined as "OneWay")

 void ColletionPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
      for (int j = 0; j < ObsColectionNum.Count; j++)
      {
            ObsColectionNum[j].Key = j + 1;
      }
 }

The moved item appears with the right key, the others keep their initial key.

What am I missing ?


Solution

  • When working with observable collections, the controls using that as ItemsSource only update the items you shifted. This means, elements that have not moved do not necessarily get rerendered.

    Looking at your code, what you are trying to do is updating UI elements created using some form of template by changing a property. In that case, the objects in your collection need to support INotifyPropertyChanged or the property you are changing needs to be dependency property for XAML to pick up changes to the properties. Also note that you should also set the binding mode to "OneWay" or "TwoWay" for those properties you expect to change.