﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" 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/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - ClientUI - explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Mon, 08 Oct 2012 04:53:40 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;In order to prevent resource leaks, you should unsubscribe from events before you dispose of a subscriber object. Until you unsubscribe from an event, the multicast delegate that underlies the event in the publishing object has a reference to the delegate that encapsulates the subscriber’s event handler. As long as the publishing object holds that reference, garbage collection will not delete your subscriber object.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;When user selects an item, initially the _selectedItem is null and the value keep the information about what the user select. In this condition, the PropertyChanged event handler is subscribed. Next, _selectedItem is set to be equal to value. OnPropertyChanged(“SelectedItem”) will be raised and the setter of SelectedItem property will get fired again. Now, _selectedItem is no longer null, and we can use it to unsubscribe the event.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Please feel free to let us know your feedback or response.&lt;/span&gt;&lt;/p&gt;
</description></item><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Fri, 05 Oct 2012 04:02:08 GMT</pubDate><dc:creator>zen8019</dc:creator><description>&lt;p&gt;We are nearly there...yes I understand &lt;b&gt;adding &lt;/b&gt;the OnPropertyChanged but why do we have to &lt;b&gt;remove &lt;/b&gt;as well&lt;b&gt;&amp;nbsp;&lt;/b&gt;under this logic:&lt;/p&gt;&lt;p /&gt;&lt;pre style="font-size: 12px; white-space: pre-wrap; word-wrap: break-word; color: rgb(63, 63, 63); line-height: 18px; "&gt;  &lt;b style="font-family: 'lucida grande', 'segoe ui', arial, verdana, tahoma; "&gt;if (_selectedItem != null)
                      _selectedItem.Contact.PropertyChanged -= new PropertyChangedEventHandler(Contact_PropertyChanged);&lt;/b&gt;&lt;/pre&gt;
&lt;p /&gt;</description></item><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Thu, 04 Oct 2012 22:51:11 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;If I’m not mistaken, the snippet code is available in the Contacts MVVM C# Sample project (start &amp;gt; All Programs &amp;gt; Intersoft WebUI Studio 2012 R1 SP1 &amp;gt; WebUI Studio for Silverlight 5 &amp;gt; Development Samples &amp;gt; Contacts MVVM C# Sample).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The subscribe and unsubscribe of PropertyChanged event are done in the setter of SelectedItem property because the sample would like to inform the OnPropertyChanged of SelectionStatus during item selection.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Thu, 04 Oct 2012 04:02:23 GMT</pubDate><dc:creator>zen8019</dc:creator><description>&lt;p&gt;I understand the code as you describe (subscribing/unsubscribing) what I wanted to know is &lt;b&gt;why &lt;/b&gt;does it have to subscribe and unsubscribe when the selected item changes&lt;/p&gt;</description></item><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Thu, 04 Oct 2012 02:29:46 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;blockquote&gt;&lt;pre&gt;...
if (value != null)
    value.Contact.PropertyChanged &amp;#43;= new PropertyChangedEventHandler(Contact_PropertyChanged);
...&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The above code will subscribe to a PropertyChanged event for value.Contact object if value doesn’t equal to null (if condition is met).&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;...
if (_selectedItem != null)
    _selectedItem.Contact.PropertyChanged -= new PropertyChangedEventHandler(Contact_PropertyChanged);
...&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The code will unsubscribe from a PropertyChanged event for selectedItem.Contact object if selectedItem doesn’t equal to null.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;For more detail information, you may check the “&lt;a href="http://msdn.microsoft.com/en-us/library/ms366768.aspx"&gt;How to: Subscribe to and Unsubscibe from Events&lt;/a&gt;”.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Hope this help.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>explanation of code</title><link>http://www.intersoftsolutions.com/Community/ClientUI/explanation-of-code/</link><pubDate>Wed, 03 Oct 2012 05:38:43 GMT</pubDate><dc:creator>zen8019</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;can you please explain the code (bolded) -  thanks&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;// Selection, View States
        public ContactViewModel SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (_selectedItem != value)
                {
                    &lt;b&gt;if (_selectedItem != null)
                        _selectedItem.Contact.PropertyChanged -= new PropertyChangedEventHandler(Contact_PropertyChanged);
                    
                    if (value != null)
                        value.Contact.PropertyChanged &amp;#43;= new PropertyChangedEventHandler(Contact_PropertyChanged);&lt;/b&gt;
                    _selectedItem = value;
                    OnPropertyChanged("SelectedItem");
                    OnPropertyChanged("SelectionStatus");
                    InvalidateCommands();
                }
            }
        }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p /&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>