0

私の WP7 プロジェクトでは、ネストされた Observable コレクションを使用しています。ただし、私の問題は、ネストされたコレクションを降順で並べ替えることです。

コレクションのデータ構造:

public class SubCategory : INotifyPropertyChanged
{
    private string _catName;
    public string CatName
    {
        get { return _catName; }
        set
        {
            _catName = value; NotifyPropertyChanged("CatName");
        }
    }

    private ObservableCollection<ToDoList> _lists;
    public ObservableCollection<ToDoList> Lists
    {
        get { return _lists; }
        set
        {

            if (_lists != value)
            {
                _lists = value;
                NotifyPropertyChanged("lists");
            }
        }
    }

そして、これはネストされたコレクションです

public class ToDoList : INotifyPropertyChanged//, INotifyPropertyChanging
{
    #region NotifyPropertyChanged Members
    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    #endregion

    #region NotifyPropertyChanging Members

   // public event PropertyChangingEventHandler PropertyChanging;
   /* private void NotifyPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
    }*/
    #endregion

    [Column(IsVersion = true)]
    private Binary _version;

    private int _ItemId;
    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int ItemId
    {
        get { return _ItemId; }
        set
        {
            if (_ItemId != value)
            {
                //NotifyPropertyChanging("ItemdId");
                _ItemId = value;
                NotifyPropertyChanged("ItemId");
            }
        }
    }

    private string _ItemTitle;
    [Column]
    public string ItemTitle
    {
        get { return _ItemTitle; }
        set
        {
            if (_ItemTitle != value)
            {
                //NotifyPropertyChanging("ItemTitle");
                _ItemTitle = value;
                NotifyPropertyChanged("ItemTitle");
            }
        }
    }

    private double _ItemLatitude;
    [Column]
    public double ItemLatitude
    {
        get { return _ItemLatitude; }
        set
        {
            if (_ItemLatitude != value)
            {
                //NotifyPropertyChanging("ItemLatitude");
                _ItemLatitude = value;
                NotifyPropertyChanged("ItemLatitude");
            }
        }
    }

    private string _ItemAddress;
    [Column]
    public string ItemAddress
    {
        get { return _ItemAddress; }
        set
        {
            if (_ItemAddress != value)
            {
                //NotifyPropertyChanging("ItemAddress");
                _ItemAddress = value;
                NotifyPropertyChanged("ItemAddress");
            }
        }
    }

    private double _ItemLongtitude;
    [Column]
    public double ItemLongtitude
    {
        get { return _ItemLongtitude; }
        set
        {
            if (_ItemLongtitude != value)
            {
                //NotifyPropertyChanging("ItemLongtitude");
                _ItemLongtitude = value;
                NotifyPropertyChanged("ItemLongtitude");
            }
        }
    }

    private string _ItemDescription;
    [Column]
    public string ItemDescription
    {
        get { return _ItemDescription; }
        set
        {
            if (_ItemDescription != value)
            {
                //NotifyPropertyChanging("ItemDescription");
                _ItemDescription = value;
                NotifyPropertyChanged("ItemDescription");
            }
        }
    }

    private bool isScheduled;
    [Column]
    public bool IsScheduled
    {
        get { return isScheduled; }
        set
        {
            if (isScheduled != value)
            {
                //NotifyPropertyChanging("IsScheduled");
                isScheduled = value;
                NotifyPropertyChanged("IsScheduled");
            }
        }
    }

    private string _reminderId;
    [Column]
    public String ReminderId
    {
        get { return _reminderId; }
        set
        {
            if (_reminderId != value)
            {
                //NotifyPropertyChanging("ReminderId");
                _reminderId = value;
                NotifyPropertyChanged("ReminderId");
            }
        }
    }

    private String _ItemTime;
    [Column]
    public String ItemTime
    {
        get { return _ItemTime; }
        set
        {
            if (_ItemTime != value)
            {
                //NotifyPropertyChanging("ItemTime");
                _ItemTime = value;
                NotifyPropertyChanged("ItemTime");
            }
        }
    }
    private bool _isComplete;
    [Column]
    public bool IsComplete
    {
        get { return _isComplete; }
        set
        {
            if (_isComplete != value)
            {
                //NotifyPropertyChanging("IsComplete");
                _isComplete = value;
                NotifyPropertyChanged("IsComplete");
            }
        }
    }
    private char _importance;
    [Column]
    public char Importance
    {
        get { return _importance; }
        set
        {
            if (_importance != value)
            {
                //NotifyPropertyChanging("Importance");
                _importance = value;
                NotifyPropertyChanged("Importance");
            }
        }
    }
    [Column]
    internal int _categoryId;

    private EntityRef<Category> _category;
    public Category ToDoCategory
    {
        get { return _category.Entity; }
        set
        {
            //NotifyPropertyChanging("ToDoCategory");
            _category.Entity = value;
            if (value != null)
            {
                _categoryId = value.CategoryId;
            }
            //NotifyPropertyChanging("ToDoCategory");
        }
    }
}
4

1 に答える 1

0

getメソッドを変更することで解決しました。これが私がした方法です。

public ObservableCollection<ToDoList> Lists
    {
        get
        {
            var l = from ToDoList lis in _lists
                    orderby lis.ItemId descending
                    select lis;
            return new ObservableCollection<ToDoList>(l);
        }
        set
        {

            if (_lists != value)
            {
                _lists = value;
                NotifyPropertyChanged("lists");
            }
        }
    }
于 2012-12-16T11:29:06.267 に答える