EnumerableCollectionView.cs :  » 2.6.4-mono-.net-core » System.Windows » System » Windows » Data » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Windows 
System.Windows » System » Windows » Data » EnumerableCollectionView.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Collections.Specialized;

namespace System.Windows.Data{

  class EnumerableCollectionView : ICollectionView, INotifyPropertyChanged, IDeferRefresh {

    ObservableCollection<object> clonedCollection;
    StandardCollectionView view;

    public event EventHandler CurrentChanged;
    public event CurrentChangingEventHandler CurrentChanging;
    public event NotifyCollectionChangedEventHandler CollectionChanged;
    public event PropertyChangedEventHandler PropertyChanged;
    
    public bool CanFilter {
      get { return view.CanFilter; }
    }

    public bool CanGroup {
      get { return view.CanGroup; }
    }

    public bool CanSort {
      get { return view.CanSort; }
    }

    public System.Globalization.CultureInfo Culture {
      get { return view.Culture; }
      set { view.Culture = value; }
    }

    public object CurrentItem {
      get { return view.CurrentItem; }
    }

    public int CurrentPosition {
      get { return view.CurrentPosition; }
    }

    int IDeferRefresh.DeferLevel {
      get { return ((IDeferRefresh) view).DeferLevel; }
      set { ((IDeferRefresh) view).DeferLevel = value; }
    }

    public Predicate<object> Filter {
      get { return view.Filter; }
      set { view.Filter = value; }
    }

    public ObservableCollection<GroupDescription> GroupDescriptions {
      get { return view.GroupDescriptions; }
    }

    public ReadOnlyObservableCollection<object> Groups {
      get { return view.Groups; }
    }

    public bool IsCurrentAfterLast {
      get { return view.IsCurrentAfterLast; }
    }

    public bool IsCurrentBeforeFirst {
      get { return view.IsCurrentBeforeFirst; }
    }

    public bool IsEmpty {
      get { return view.IsEmpty; }
    }

    public SortDescriptionCollection SortDescriptions {
      get { return view.SortDescriptions; }
    }

    public IEnumerable SourceCollection {
      get; private set;
    }

    public EnumerableCollectionView (IEnumerable collection)
    {
      SourceCollection = collection;

      clonedCollection = new ObservableCollection<object> (collection.Cast <object> ());
      view = new StandardCollectionView (clonedCollection);

      var c = collection as INotifyCollectionChanged;
      if (c != null)
        c.CollectionChanged += HandleCollectionChanged;

      view.CollectionChanged += (o, e) => {
        var h = CollectionChanged;
        if (h != null)
          h (this, e);
      };
      view.CurrentChanged += (o, e) => {
        var h = CurrentChanged;
        if (h != null)
          h (this, e);
      };
      view.CurrentChanging += (o, e) => {
        var h = CurrentChanging;
        if (h != null)
          h (this, e);
      };
      view.PropertyChanged += (o, e) => {
        var h = PropertyChanged;
        if (h != null)
          h (this, e);
      };
    }

    void HandleCollectionChanged (object sender, NotifyCollectionChangedEventArgs e)
    {
      switch (e.Action) {
      case NotifyCollectionChangedAction.Add:
        for (int i = 0; i < e.NewItems.Count; i++)
          clonedCollection.Insert (e.NewStartingIndex + i, e.NewItems [i]);
        break;
      case NotifyCollectionChangedAction.Remove:
        for (int i = e.OldItems.Count; i > 0; i--)
          clonedCollection.RemoveAt (e.OldStartingIndex);
        break;

      case NotifyCollectionChangedAction.Replace:
        for (int i = 0; i < e.OldItems.Count; i++)
          clonedCollection[e.OldStartingIndex + i] = e.NewItems [i];
        break;
      case NotifyCollectionChangedAction.Reset:
        clonedCollection.Clear ();
        foreach (var v in SourceCollection)
          clonedCollection.Add (v);
        break;
      default:
        throw new NotSupportedException ();
      }
    }

    public bool Contains (object item)
    {
      return view.Contains (item);
    }

    public IDisposable DeferRefresh ()
    {
      return view.DeferRefresh ();
    }

    public bool MoveCurrentTo (object item)
    {
      return view.MoveCurrentTo (item);
    }

    public bool MoveCurrentToFirst ()
    {
      return view.MoveCurrentToFirst ();
    }

    public bool MoveCurrentToLast ()
    {
      return view.MoveCurrentToLast ();
    }

    public bool MoveCurrentToNext ()
    {
      return view.MoveCurrentToNext ();
    }

    public bool MoveCurrentToPosition (int position)
    {
      return view.MoveCurrentToPosition (position);
    }

    public bool MoveCurrentToPrevious ()
    {
      return view.MoveCurrentToPrevious ();
    }

    public void Refresh ()
    {
      view.Refresh ();
    }

    public IEnumerator GetEnumerator ()
    {
      return view.GetEnumerator ();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.