<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to AddRange/RemoveRange in Silverlight ObservableCollection&lt;T&gt;?</title>
	<atom:link href="http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/feed/" rel="self" type="application/rss+xml" />
	<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/</link>
	<description>Take care of the sense, and the sounds will take care of themselves.</description>
	<lastBuildDate>Wed, 08 Feb 2012 19:14:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Royce Tucker</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-4736</link>
		<dc:creator>Royce Tucker</dc:creator>
		<pubDate>Fri, 18 Nov 2011 20:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-4736</guid>
		<description>The problem here is that you are using NotifyCollectionChangedAction.Reset when you send the collection changed event. This enum value is reserved for when the entire collection needs to be completely reloaded. 

The correct logic would set the OldItems and NewItems properties on the NotifyCollectionChangedEventArgs variable and send an event with an Action of NotifyCollectionChangedAction.Add or .Remove.</description>
		<content:encoded><![CDATA[<p>The problem here is that you are using NotifyCollectionChangedAction.Reset when you send the collection changed event. This enum value is reserved for when the entire collection needs to be completely reloaded. </p>
<p>The correct logic would set the OldItems and NewItems properties on the NotifyCollectionChangedEventArgs variable and send an event with an Action of NotifyCollectionChangedAction.Add or .Remove.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - May 13, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-1410</link>
		<dc:creator>Dew Drop - May 13, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Thu, 01 Jan 2009 08:48:03 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-1410</guid>
		<description>&lt;p&gt;Pingback from &#160;Dew Drop - May 13, 2008 &#124; Alvin Ashcraft&#039;s Morning Dew&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Pingback from &nbsp;Dew Drop &#8211; May 13, 2008 | Alvin Ashcraft&#8217;s Morning Dew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Community Blogs</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-1409</link>
		<dc:creator>Community Blogs</dc:creator>
		<pubDate>Thu, 01 Jan 2009 08:48:02 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-1409</guid>
		<description>&lt;p&gt;Joel Neubeck animates user controls, Tim Rule on Scale 9 Images, and Tamir Khason On manipulating ObservableCollection&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Joel Neubeck animates user controls, Tim Rule on Scale 9 Images, and Tamir Khason On manipulating ObservableCollection</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blogumdan</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-1408</link>
		<dc:creator>Blogumdan</dc:creator>
		<pubDate>Thu, 01 Jan 2009 08:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-1408</guid>
		<description>&lt;p&gt;İ cant do it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>İ cant do it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chaiguy1337</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-1407</link>
		<dc:creator>chaiguy1337</dc:creator>
		<pubDate>Thu, 01 Jan 2009 08:47:58 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-1407</guid>
		<description>&lt;p&gt;When using modal modifiers like deferNotification, it is important to always wrap the reset in a &quot;finally&quot; block, in case an exception happens somewhere above. Otherwise, your class may be left in an inconsistent state:&lt;/p&gt;
&lt;p&gt;try {&lt;/p&gt;
&lt;p&gt; &#160; deferNotification = true;&lt;/p&gt;
&lt;p&gt; &#160; ...&lt;/p&gt;
&lt;p&gt;} finally {&lt;/p&gt;
&lt;p&gt; &#160; deferNotification = false;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>When using modal modifiers like deferNotification, it is important to always wrap the reset in a &quot;finally&quot; block, in case an exception happens somewhere above. Otherwise, your class may be left in an inconsistent state:</p>
<p>try {</p>
<p> &nbsp; deferNotification = true;</p>
<p> &nbsp; &#8230;</p>
<p>} finally {</p>
<p> &nbsp; deferNotification = false;</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geert van Horrik</title>
		<link>http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/comment-page-1/#comment-1406</link>
		<dc:creator>Geert van Horrik</dc:creator>
		<pubDate>Thu, 01 Jan 2009 08:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/how-to-addrangeremoverange-in-silverlight-observablecollectiont/#comment-1406</guid>
		<description>&lt;p&gt;Don&#039;t forget to check whether the collection has actually changed in the AddRange or RemoveRange (for example, what if the collection is empty)?&lt;/p&gt;
&lt;p&gt;I made some small modifications:&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160;public void AddRange(IEnumerable&lt;T&gt; collection)&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160;{&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;// Declare variables&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;bool collectionChanged = false;&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;// Don&#039;t update&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;_deferNotification = true;&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;try&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;{&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;// Add all items&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;foreach (T itm in collection)&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;{&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;// Add item&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;Add(itm);&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;// Collection has changed&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;collectionChanged = true;&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;}&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;finally&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;{&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;// Notify again&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;_deferNotification = false;&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;}&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;// Collection has changed&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;if (collectionChanged)&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;{&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160; &#160; &#160;}&lt;/p&gt;
&lt;p&gt; &#160; &#160; &#160; &#160;}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Don&#8217;t forget to check whether the collection has actually changed in the AddRange or RemoveRange (for example, what if the collection is empty)?</p>
<p>I made some small modifications:</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp;public void AddRange(IEnumerable&lt;T&gt; collection)</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp;{</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Declare variables</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bool collectionChanged = false;</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Don&#8217;t update</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_deferNotification = true;</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Add all items</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;foreach (T itm in collection)</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Add item</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Add(itm);</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Collection has changed</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;collectionChanged = true;</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;finally</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Notify again</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_deferNotification = false;</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Collection has changed</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (collectionChanged)</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p> &nbsp; &nbsp; &nbsp; &nbsp;}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

