Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please take a look at the <code>BindableCollection&lt;T&gt;</code> from <strong>Caliburn.Micro</strong> library:</p> <pre><code>/// &lt;summary&gt; /// A base collection class that supports automatic UI thread marshalling. /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;The type of elements contained in the collection.&lt;/typeparam&gt; #if !SILVERLIGHT &amp;&amp; !WinRT [Serializable] #endif public class BindableCollection&lt;T&gt; : ObservableCollection&lt;T&gt;, IObservableCollection&lt;T&gt; { /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref = "Caliburn.Micro.BindableCollection{T}" /&gt; class. /// &lt;/summary&gt; public BindableCollection() { IsNotifying = true; } /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref = "Caliburn.Micro.BindableCollection{T}" /&gt; class. /// &lt;/summary&gt; /// &lt;param name = "collection"&gt;The collection from which the elements are copied.&lt;/param&gt; /// &lt;exception cref = "T:System.ArgumentNullException"&gt; /// The &lt;paramref name = "collection" /&gt; parameter cannot be null. /// &lt;/exception&gt; public BindableCollection(IEnumerable&lt;T&gt; collection) : base(collection) { IsNotifying = true; } #if !SILVERLIGHT &amp;&amp; !WinRT [field: NonSerialized] #endif bool isNotifying; //serializator try to serialize even autogenerated fields /// &lt;summary&gt; /// Enables/Disables property change notification. /// &lt;/summary&gt; #if !WinRT [Browsable(false)] #endif public bool IsNotifying { get { return isNotifying; } set { isNotifying = value; } } /// &lt;summary&gt; /// Notifies subscribers of the property change. /// &lt;/summary&gt; /// &lt;param name = "propertyName"&gt;Name of the property.&lt;/param&gt; #if WinRT || NET45 public virtual void NotifyOfPropertyChange([CallerMemberName]string propertyName = "") { #else public virtual void NotifyOfPropertyChange(string propertyName) { #endif if(IsNotifying) Execute.OnUIThread(() =&gt; OnPropertyChanged(new PropertyChangedEventArgs(propertyName))); } /// &lt;summary&gt; /// Raises a change notification indicating that all bindings should be refreshed. /// &lt;/summary&gt; public void Refresh() { Execute.OnUIThread(() =&gt; { OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }); } /// &lt;summary&gt; /// Inserts the item to the specified position. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The index to insert at.&lt;/param&gt; /// &lt;param name = "item"&gt;The item to be inserted.&lt;/param&gt; protected override sealed void InsertItem(int index, T item) { Execute.OnUIThread(() =&gt; InsertItemBase(index, item)); } /// &lt;summary&gt; /// Exposes the base implementation of the &lt;see cref = "InsertItem" /&gt; function. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The index.&lt;/param&gt; /// &lt;param name = "item"&gt;The item.&lt;/param&gt; /// &lt;remarks&gt; /// Used to avoid compiler warning regarding unverifiable code. /// &lt;/remarks&gt; protected virtual void InsertItemBase(int index, T item) { base.InsertItem(index, item); } #if NET || WP8 || WinRT /// &lt;summary&gt; /// Moves the item within the collection. /// &lt;/summary&gt; /// &lt;param name="oldIndex"&gt;The old position of the item.&lt;/param&gt; /// &lt;param name="newIndex"&gt;The new position of the item.&lt;/param&gt; protected sealed override void MoveItem(int oldIndex, int newIndex) { Execute.OnUIThread(() =&gt; MoveItemBase(oldIndex, newIndex)); } /// &lt;summary&gt; /// Exposes the base implementation fo the &lt;see cref="MoveItem"/&gt; function. /// &lt;/summary&gt; /// &lt;param name="oldIndex"&gt;The old index.&lt;/param&gt; /// &lt;param name="newIndex"&gt;The new index.&lt;/param&gt; /// &lt;remarks&gt;Used to avoid compiler warning regarding unverificable code.&lt;/remarks&gt; protected virtual void MoveItemBase(int oldIndex, int newIndex) { base.MoveItem(oldIndex, newIndex); } #endif /// &lt;summary&gt; /// Sets the item at the specified position. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The index to set the item at.&lt;/param&gt; /// &lt;param name = "item"&gt;The item to set.&lt;/param&gt; protected override sealed void SetItem(int index, T item) { Execute.OnUIThread(() =&gt; SetItemBase(index, item)); } /// &lt;summary&gt; /// Exposes the base implementation of the &lt;see cref = "SetItem" /&gt; function. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The index.&lt;/param&gt; /// &lt;param name = "item"&gt;The item.&lt;/param&gt; /// &lt;remarks&gt; /// Used to avoid compiler warning regarding unverifiable code. /// &lt;/remarks&gt; protected virtual void SetItemBase(int index, T item) { base.SetItem(index, item); } /// &lt;summary&gt; /// Removes the item at the specified position. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The position used to identify the item to remove.&lt;/param&gt; protected override sealed void RemoveItem(int index) { Execute.OnUIThread(() =&gt; RemoveItemBase(index)); } /// &lt;summary&gt; /// Exposes the base implementation of the &lt;see cref = "RemoveItem" /&gt; function. /// &lt;/summary&gt; /// &lt;param name = "index"&gt;The index.&lt;/param&gt; /// &lt;remarks&gt; /// Used to avoid compiler warning regarding unverifiable code. /// &lt;/remarks&gt; protected virtual void RemoveItemBase(int index) { base.RemoveItem(index); } /// &lt;summary&gt; /// Clears the items contained by the collection. /// &lt;/summary&gt; protected override sealed void ClearItems() { Execute.OnUIThread(ClearItemsBase); } /// &lt;summary&gt; /// Exposes the base implementation of the &lt;see cref = "ClearItems" /&gt; function. /// &lt;/summary&gt; /// &lt;remarks&gt; /// Used to avoid compiler warning regarding unverifiable code. /// &lt;/remarks&gt; protected virtual void ClearItemsBase() { base.ClearItems(); } /// &lt;summary&gt; /// Raises the &lt;see cref = "E:System.Collections.ObjectModel.ObservableCollection`1.CollectionChanged" /&gt; event with the provided arguments. /// &lt;/summary&gt; /// &lt;param name = "e"&gt;Arguments of the event being raised.&lt;/param&gt; protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (IsNotifying) { base.OnCollectionChanged(e); } } /// &lt;summary&gt; /// Raises the PropertyChanged event with the provided arguments. /// &lt;/summary&gt; /// &lt;param name = "e"&gt;The event data to report in the event.&lt;/param&gt; protected override void OnPropertyChanged(PropertyChangedEventArgs e) { if (IsNotifying) { base.OnPropertyChanged(e); } } /// &lt;summary&gt; /// Adds the range. /// &lt;/summary&gt; /// &lt;param name = "items"&gt;The items.&lt;/param&gt; public virtual void AddRange(IEnumerable&lt;T&gt; items) { Execute.OnUIThread(() =&gt; { var previousNotificationSetting = IsNotifying; IsNotifying = false; var index = Count; foreach(var item in items) { InsertItemBase(index, item); index++; } IsNotifying = previousNotificationSetting; OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }); } /// &lt;summary&gt; /// Removes the range. /// &lt;/summary&gt; /// &lt;param name = "items"&gt;The items.&lt;/param&gt; public virtual void RemoveRange(IEnumerable&lt;T&gt; items) { Execute.OnUIThread(() =&gt; { var previousNotificationSetting = IsNotifying; IsNotifying = false; foreach(var item in items) { var index = IndexOf(item); if (index &gt;= 0) { RemoveItemBase(index); } } IsNotifying = previousNotificationSetting; OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }); } /// &lt;summary&gt; /// Called when the object is deserialized. /// &lt;/summary&gt; /// &lt;param name="c"&gt;The streaming context.&lt;/param&gt; [OnDeserialized] public void OnDeserialized(StreamingContext c) { IsNotifying = true; } /// &lt;summary&gt; /// Used to indicate whether or not the IsNotifying property is serialized to Xml. /// &lt;/summary&gt; /// &lt;returns&gt;Whether or not to serialize the IsNotifying property. The default is false.&lt;/returns&gt; public virtual bool ShouldSerializeIsNotifying() { return false; } } </code></pre> <p><a href="https://caliburnmicro.codeplex.com/SourceControl/latest#src/Caliburn.Micro.Silverlight/INPC.cs" rel="nofollow">Source</a></p> <p>PS. Just take in mind that this class use some other classes from Caliburn.Micro so that you could either copy/pase all dependencies by your-self - OR - if you are not using any other application frameworks - just reference the library binary and give it a chance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload