<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#124; Limilabs &#187; MVVM</title>
	<atom:link href="http://www.limilabs.com/blog/tag/mvvm/feed" rel="self" type="application/rss+xml" />
	<link>http://www.limilabs.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 21 May 2012 09:49:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>INotifyPropertyChanged with lambdas</title>
		<link>http://www.limilabs.com/blog/inotifypropertychanged-with-lambdas?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inotifypropertychanged-with-lambdas</link>
		<comments>http://www.limilabs.com/blog/inotifypropertychanged-with-lambdas#comments</comments>
		<pubDate>Tue, 16 Feb 2010 21:48:22 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=475</guid>
		<description><![CDATA[There are several ways of implementing INotifyPropertyChanged in WPF applications. One that I particularly like is by using PostSharp to implement INotifyPropertyChanged. If you are not comfortable with PostSharp you can at least get rid of those nasty strings in standard implementation: public class Model : ViewModeBase { private string _status; public string Status { [...]]]></description>
			<content:encoded><![CDATA[<p>There are several ways of implementing <em>INotifyPropertyChanged</em> in WPF applications.</p>
<p>One that I particularly like is by using <a href="http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp">PostSharp to implement INotifyPropertyChanged</a>.</p>
<p>If you are not comfortable with PostSharp you can at least get rid of those nasty strings in standard implementation:</p>
<pre class="brush: csharp;">
public class Model : ViewModeBase
{
    private string _status;
    public string Status
    {
        get { return _status; }
        set
        {
            _status = value;
            OnPropertyChanged(&quot;Status&quot;);
        }
    }
};
</pre>
<p>Labda expressions look nicer and are easier to refactor:</p>
<pre class="brush: csharp;">
public class MyModel : ViewModeBase
{
    private string _status;
    public string Status
    {
        get { return _status; }
        set
        {
            _status = value;
            OnPropertyChanged(() =&gt; Status);
        }
    }
};
</pre>
<p>First thing we need to do is to create base class for all our ViewModels:</p>
<pre class="brush: csharp;">
public class ViewModelBase
{
    public event PropertyChangedEventHandler PropertyChanged
        = delegate { };

    protected void OnPropertyChanged(
        Expression&lt;func&lt;object&gt;&gt; expression)
    {
        string propertyName = PropertyName.For(expression);
        this.PropertyChanged(
            this,
            new PropertyChangedEventArgs(propertyName));
    }
};
</pre>
<p>The implementation of PropertyName.For is very straightforward: <a href="http://www.limilabs.com/blog/property-name-from-lambda">How to get property name from lambda</a>.</p>
<p>That&#8217;s it!<br />
Nice, easy to refactor, compile-time checked <em>INotifyPropertyChanged</em> implementation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/inotifypropertychanged-with-lambdas/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>M-V-VM talk</title>
		<link>http://www.limilabs.com/blog/m-v-vm-talk?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=m-v-vm-talk</link>
		<comments>http://www.limilabs.com/blog/m-v-vm-talk#comments</comments>
		<pubDate>Tue, 13 Oct 2009 08:49:58 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Presentation]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=184</guid>
		<description><![CDATA[Here are the slide-show and code from my recent M-V-VM talk on the Warsaw .NET group. I was talking about different flavors of MVVM, blendability, unit testing and separation of concerns. All in all, I think it was a good talk with great audience participation. MVVM_Presentation MyMVVMSample]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.limilabs.com/blog/wp-content/uploads/2009/10/thumbnail.jpeg" alt="thumbnail" title="thumbnail" width="256" height="192" class="alignleft size-full wp-image-185" /><br />
Here are the slide-show and code from my recent M-V-VM talk on the Warsaw .NET group. I was talking about different flavors of MVVM, blendability, unit testing and separation of concerns. All in all, I think it was a good talk with great audience participation.</p>
<p><a href='http://www.limilabs.com/blog/wp-content/uploads/2009/10/MVVM_Presentation.pptx'>MVVM_Presentation</a><br />
<a href='http://www.limilabs.com/blog/wp-content/uploads/2009/10/MyMVVMSample.zip'>MyMVVMSample</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/m-v-vm-talk/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>INotifyPropertyChanged with PostSharp 1.5</title>
		<link>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inotifypropertychanged-with-postsharp</link>
		<comments>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp#comments</comments>
		<pubDate>Tue, 15 Sep 2009 12:03:01 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[PostSharp]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=14</guid>
		<description><![CDATA[If you are doing WPF development, most likely you are tired of writing property implementations that raise PropertyChanged event manually: public class MainWindowViewModel : ViewModel { private string _message; public string Message { get { return _message; } set { _message = value; OnPropertyChanged(&#34;Message&#34;); } } // ... } PostSharp is a great tool to [...]]]></description>
			<content:encoded><![CDATA[<p>If you are doing WPF development, most likely you are tired of writing property implementations that raise <em>PropertyChanged</em> event manually:</p>
<pre class="brush: csharp;">
public class MainWindowViewModel : ViewModel
{
    private string _message;

    public string Message
    {
        get
        {
            return _message;
        }
        set
        {
            _message = value;
            OnPropertyChanged(&quot;Message&quot;);
        }
    }

    // ...
}
</pre>
<p><a href="http://www.postsharp.org">PostSharp</a> is a great tool to make such things simplier.</p>
<p>Let&#8217;s look at the specific ViewModel class that has a <em>Message</em> property that is <strong>bound to some UI element</strong> using XAML:</p>
<pre class="brush: csharp;">
public class MainWindowViewModel : ViewModel
{
    [RaisePropertyChanged]
    public string Message { get; set; }

    // ...
}
</pre>
<p> Notice the <em>RaisePropertyChanged</em> attribute, which we&#8217;ll implement later.</p>
<p>Here&#8217;s our <strong>base ViewModel</strong> class that provides <strong>actual implementation</strong> of the <em>INotifyPropertyChanged</em> interface:</p>
<pre class="brush: csharp;">
public class ViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged
        = delegate { };

    public void OnPropertyChanged(string propertyName)
    {
        PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
    }
};
</pre>
<p>Finally the PostSharp attribute:</p>
<pre class="brush: csharp;">
[Serializable]  // required by PostSharp
public class RaisePropertyChangedAttribute : OnMethodBoundaryAspect
{
    private string _propertyName;

    /// &lt;summary&gt;
    /// Executed at runtime, after the method.
    /// &lt;/summary&gt;
    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        ViewModel viewModel = (ViewModel)eventArgs.Instance;
        viewModel.OnPropertyChanged(_propertyName);
    }

    public override bool CompileTimeValidate(MethodBase method)
    {
        if (IsPropertySetter(method))
        {
            _propertyName = GetPropertyName(method);
            return true;
        }
        return false;
    }

    private static string GetPropertyName(MethodBase method)
    {
        return method.Name.Replace&quot;set_&quot;, &quot;&quot;);
    }

    private static bool IsPropertySetter(MethodBase method)
    {
        return method.Name.StartsWith(&quot;set_&quot;);
    }
};
</pre>
<p>Note that we are validating if the method is in fact a property only during <strong>compilation time</strong> using <em>CompileTimeValidate</em> method.</p>
<p>During compile time appropriate invocations of <em>OnPropertyChanged</em> method will be <strong>injected after every set operation</strong> applied to the <em>Message</em> property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

