<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Here&#039;s - nnish! Nishanth Anil &#187; nnish</title>
	<atom:link href="http://nnish.com/author/nnish/feed/" rel="self" type="application/rss+xml" />
	<link>http://nnish.com</link>
	<description>My Passions Live Here!</description>
	<lastBuildDate>Wed, 23 May 2012 17:41:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nnish.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/8c82fa2fb7ce977e736ec7cd632713a8?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Here&#039;s - nnish! Nishanth Anil &#187; nnish</title>
		<link>http://nnish.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nnish.com/osd.xml" title="Here&#039;s - nnish! Nishanth Anil" />
	<atom:link rel='hub' href='http://nnish.com/?pushpress=hub'/>
		<item>
		<title>Attached Behaviors &amp; MVVM</title>
		<link>http://nnish.com/2012/04/22/attached-behaviors-mvvm/</link>
		<comments>http://nnish.com/2012/04/22/attached-behaviors-mvvm/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 08:16:41 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/?p=240</guid>
		<description><![CDATA[When you think of MVVM and other patterns involved, it is often about separation of concerns as much as possible, unit testability and code maintainability. These type of patterns help in high quality of code and efficient development of business functionality. If you are new to MVVM then you may want to check out some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=240&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you think of MVVM and other patterns involved, it is often about separation of concerns as much as possible, unit testability and code maintainability. These type of patterns help in high quality of code and efficient development of business functionality. If you are new to MVVM then you may want to check out some of the articles by various intellects like <a href="http://joshsmithonwpf.wordpress.com/">Josh Smith</a>, <a href="http://www.galasoft.ch/">Laurent Bugnion</a> and few others from <a href="http://groups.google.com/group/wpf-disciples">XAML Disciples</a> group(or just <a href="https://www.google.co.in/search?q=mvvm">Google</a>&#160;<img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://nnish.files.wordpress.com/2012/04/wlemoticon-smile.png?w=600" />). </p>
<p>There are lot many frameworks on MVVM out there and to be frank there isn’t any right or the wrong one. You need to evaluate and decide on the one that fits your need! Most often people land up writing one on their own and in a way it is good!</p>
<p>I personally like a framework written by <a href="https://brettedotnet.wordpress.com/">Brette Esterbrooks</a> because it is a skeleton of code that you need and helps you get started. I tweaked it a bit(basically removed the ones that I don’t need) and thus the sample attached on this blog will have a tiny little framework of MVVM.</p>
<p>All it has is just a few helper classes:</p>
<ol>
<li>ViewBase, </li>
<li>ViewModelBase,</li>
<li>RelayCommand, </li>
<li>ObservableObject.</li>
</ol>
<h1>Attached Behaviors</h1>
<p>&#160;</p>
<p>Attached behavior is achieved by simply attaching a behavior to a control that otherwise wouldn’t have anything of its own. </p>
<p>And as per Josh Smith-</p>
<blockquote><p>The idea is that you set an attached property on an element so that you can gain access to the element from the class that exposes the attached property. Once that class has access to the element, it can hook events on it and, in response to those events firing, make the element do things that it normally would not do. It is a very convenient alternative to creating and using subclasses, and is very XAML-friendly.</p>
</blockquote>
<p>Ever since I am hooked to MVVM pattern, I try and avoid all the code that usually goes to the code behind. For e.g. a click event handler usually written in the code behind can be omitted and a RelayCommand in the ViewModel be used instead.</p>
<p><strong><em>But what would happen if you want to handle a double click or a focus event of a control? Just retaining those kind of events to the code behind defeats the pattern itself. And thus Attached Behavior comes to rescue!</em></strong> Demo included in this post explains the DragDropBehavior.</p>
<p>Before you go further with this approach, I just want you to know that you can achieve this by <a href="http://msdn.microsoft.com/en-us/library/ff726531(v=expression.40).aspx">Behavior&lt;T&gt;</a> class included in the <em>system.windows.interactivity.dll</em>. However this dll is available only through Expression Blend installation. </p>
<p>In my demo I have explained both of the implementation and it’s usage. Here we go!</p>
<h1>Screenshot of the Demo:</h1>
<p>&#160;</p>
<p><a href="http://nnish.files.wordpress.com/2012/04/attachedbimage.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="AttachedBImage" border="0" alt="AttachedBImage" src="http://nnish.files.wordpress.com/2012/04/attachedbimage_thumb.png?w=599&h=259" width="599" height="259" /></a></p>
<p>&#160;</p>
<h1>IBehavior</h1>
<p>&#160;</p>
<p>The view models can hold the reference of this contract and change at runtime if needed:</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7a96a803-2cf5-43a0-a169-bb0101372d5d" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IBehavior</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">void</span> OnEnabled(<span style="color:#2b91af;">DependencyObject</span> dependencyObject);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">void</span> OnDisabling(<span style="color:#2b91af;">DependencyObject</span> dependencyObject);</li>
<li>    }</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>&#160;</p>
<h1>AttachedBehavior – A static class!</h1>
<p>&#160;</p>
<p>A static class AttachedBehavior is introduced which holds the attached properties “Behavior” and “IsEnabled”. </p>
<blockquote><p>When toggled from Enabled state to Disabled State &#8211; OnDisabling() method of the IBehavior is called. Use this method to unwire your event handlers.</p>
<p>&#160;</p>
</blockquote>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:681812e7-4365-446e-91ee-5f0bf09a623d" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;white-space:nowrap;">
<li> <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#808080;">///</span><span style="color:#008000;"> Attach a Behavior of type IBehavior</span></li>
<li>        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> BehaviorProperty = <span style="color:#2b91af;">DependencyProperty</span>.RegisterAttached(<span style="color:#a31515;">&quot;Behavior&quot;</span>, <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">IBehavior</span>), <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">AttachedBehavior</span>), <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">UIPropertyMetadata</span>(<span style="color:#0000ff;">null</span>));</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>        <span style="color:#808080;">///</span><span style="color:#008000;"> Is Enabled, when set to true, fires Behaviors OnEnabled Method</span></li>
<li style="background:#f3f3f3;">        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> IsEnabledProperty = <span style="color:#2b91af;">DependencyProperty</span>.RegisterAttached(<span style="color:#a31515;">&quot;IsEnabled&quot;</span>, <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">bool</span>), <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">AttachedBehavior</span>), <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">UIPropertyMetadata</span>(<span style="color:#0000ff;">false</span>, OnIsEnabledChanged));</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#808080;">///</span><span style="color:#008000;"> Handles IsEnabledChanged</span></li>
<li>        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&quot;d&quot;&gt;&lt;/param&gt;</span></li>
<li>        <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&quot;e&quot;&gt;&lt;/param&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> OnIsEnabledChanged(<span style="color:#2b91af;">DependencyObject</span> d, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span> e)</li>
<li>        {</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">if</span> (d == <span style="color:#0000ff;">null</span>)</li>
<li>                <span style="color:#0000ff;">return</span>;</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">var</span> behavior = GetBehavior(d);</li>
<li>            <span style="color:#0000ff;">if</span> (behavior == <span style="color:#0000ff;">null</span>)</li>
<li style="background:#f3f3f3;">                <span style="color:#0000ff;">return</span>;</li>
<li>            <span style="color:#0000ff;">if</span> ((<span style="color:#0000ff;">bool</span>)e.NewValue)</li>
<li style="background:#f3f3f3;">                behavior.OnEnabled(d);</li>
<li>            <span style="color:#0000ff;">else</span></li>
<li style="background:#f3f3f3;">                behavior.OnDisabling(d);</li>
<li>        }</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<h1>DragDropBehavior Class </h1>
<p>&#160;</p>
<p>DragDropBehavior class implements the IBehavior. Have a look at the OnEnabled and OnDisabling methods.</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e9efaba-baa1-4acc-a666-b8f3515e5604" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;white-space:nowrap;">
<li> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">DragDropBehavior</span> : <span style="color:#2b91af;">IBehavior</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">#region</span> Private Fields</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">Point</span> _startPosition;</li>
<li>        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">Point</span> _mouseStartPosition;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">TranslateTransform</span> _translatetransform;</li>
<li>        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">UIElement</span> _associatedObject = <span style="color:#0000ff;">null</span>;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">Window</span> _parent = <span style="color:#0000ff;">null</span>;</li>
<li>        <span style="color:#0000ff;">#endregion</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>        <span style="color:#0000ff;">#region</span> IBehavior Members</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> OnEnabled(<span style="color:#2b91af;">DependencyObject</span> dependencyObject)</li>
<li>        {</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">var</span> uiElement = dependencyObject <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">UIElement</span>;</li>
<li>            <span style="color:#0000ff;">if</span> (uiElement == <span style="color:#0000ff;">null</span>)</li>
<li style="background:#f3f3f3;">                <span style="color:#0000ff;">return</span>;</li>
<li>            </li>
<li style="background:#f3f3f3;">            _associatedObject = uiElement;</li>
<li>            <span style="color:#008000;">//</span><span style="color:#00008b;">TODO: set the parent accordingly</span></li>
<li style="background:#f3f3f3;">             _parent = <span style="color:#2b91af;">Application</span>.Current.MainWindow;</li>
<li>            _translatetransform = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">TranslateTransform</span>();</li>
<li style="background:#f3f3f3;">            _associatedObject.RenderTransform = _translatetransform;</li>
<li>            _associatedObject.MouseLeftButtonDown += AssociatedObjectMouseLeftButtonDown;</li>
<li style="background:#f3f3f3;">            _associatedObject.MouseLeftButtonUp += AssociatedObjectMouseLeftButtonUp;</li>
<li>            _associatedObject.MouseMove += AssociatedObjectMouseMove;</li>
<li style="background:#f3f3f3;">        }</li>
<li>        </li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> OnDisabling(<span style="color:#2b91af;">DependencyObject</span> dependencyObject)</li>
<li>        {</li>
<li style="background:#f3f3f3;">            _associatedObject.MouseLeftButtonDown -= AssociatedObjectMouseLeftButtonDown;</li>
<li>            _associatedObject.MouseLeftButtonUp -= AssociatedObjectMouseLeftButtonUp;</li>
<li style="background:#f3f3f3;">            _associatedObject.MouseMove -= AssociatedObjectMouseMove;</li>
<li>            _translatetransform = <span style="color:#0000ff;">null</span>;</li>
<li style="background:#f3f3f3;">        }</li>
<li>        <span style="color:#0000ff;">#endregion</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>        <span style="color:#0000ff;">#region</span> Event Handlers</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">void</span> AssociatedObjectMouseLeftButtonDown(<span style="color:#0000ff;">object</span> sender, System.Windows.Input.<span style="color:#2b91af;">MouseButtonEventArgs</span> e)</li>
<li>        {</li>
<li style="background:#f3f3f3;">            _startPosition = _associatedObject.TranslatePoint(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Point</span>(), _parent);</li>
<li>            _mouseStartPosition = e.GetPosition(_parent);</li>
<li style="background:#f3f3f3;">            _associatedObject.CaptureMouse();</li>
<li>        }</li>
<li style="background:#f3f3f3;">        </li>
<li>        <span style="color:#0000ff;">void</span> AssociatedObjectMouseMove(<span style="color:#0000ff;">object</span> sender, System.Windows.Input.<span style="color:#2b91af;">MouseEventArgs</span> e)</li>
<li style="background:#f3f3f3;">        {</li>
<li>            <span style="color:#0000ff;">var</span> positionDifference = e.GetPosition(_parent) &#8211; _mouseStartPosition;</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">if</span>(_associatedObject.IsMouseCaptured)</li>
<li>            {</li>
<li style="background:#f3f3f3;">                _translatetransform.X = positionDifference.X;</li>
<li>                _translatetransform.Y = positionDifference.Y;</li>
<li style="background:#f3f3f3;">            }</li>
<li>        }</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>        <span style="color:#0000ff;">void</span> AssociatedObjectMouseLeftButtonUp(<span style="color:#0000ff;">object</span> sender, System.Windows.Input.<span style="color:#2b91af;">MouseButtonEventArgs</span> e)</li>
<li style="background:#f3f3f3;">        {</li>
<li>            _associatedObject.ReleaseMouseCapture();</li>
<li style="background:#f3f3f3;">            </li>
<li>        }</li>
<li style="background:#f3f3f3;">        </li>
<li>        <span style="color:#0000ff;">#endregion</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">    }</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<h1>HelloView</h1>
<p>&#160;</p>
<p>Attach is the behavior to the control that you want to drag:</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1d8b7461-ce55-4e34-a4d5-f1f15b890802" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;white-space:nowrap;">
<li><span style="color:#a31515;"> </span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">ToggleButton</span><span style="color:#ff0000;"> Name</span><span style="color:#0000ff;">=&quot;dragDropToggleButton&quot;</span><span style="color:#ff0000;"> Command</span><span style="color:#0000ff;">=&quot;{</span><span style="color:#a31515;">Binding</span><span style="color:#ff0000;"> ToggleDragDropBehavior}</span><span style="color:#0000ff;">&quot;</span><span style="color:#ff0000;"> Width</span><span style="color:#0000ff;">=&quot;200&quot;&gt;</span></li>
<li style="background:#f3f3f3;">                <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">ToggleButton.Style</span><span style="color:#0000ff;">&gt;</span></li>
<li>                    <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Style</span><span style="color:#ff0000;"> TargetType</span><span style="color:#0000ff;">=&quot;{</span><span style="color:#a31515;">x</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">Type</span><span style="color:#ff0000;"> ToggleButton}</span><span style="color:#0000ff;">&quot;&gt;</span></li>
<li style="background:#f3f3f3;">                        <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Setter</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">=&quot;Content&quot;</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">=&quot;Start Dragging&quot;/&gt;</span></li>
<li>                        <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Style.Triggers</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">                            <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Trigger</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">=&quot;IsChecked&quot;</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">=&quot;True&quot;&gt;</span></li>
<li>                                <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Setter</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">=&quot;Content&quot;</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">=&quot;Stop Dragging&quot;/&gt;</span></li>
<li style="background:#f3f3f3;">                            <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">Trigger</span><span style="color:#0000ff;">&gt;</span></li>
<li>                        <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">Style.Triggers</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">                    <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">Style</span><span style="color:#0000ff;">&gt;</span></li>
<li>                <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">ToggleButton.Style</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">            <span style="color:#a31515;"></span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">ToggleButton</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>   <span style="color:#a31515;"></span></li>
<li style="background:#f3f3f3;">  <span style="color:#a31515;">            </span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">TextBlock</span><span style="color:#ff0000;"> Background</span><span style="color:#0000ff;">=&quot;Gold&quot;</span></li>
<li>                      <span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">=&quot;dragMe using attached behavior&quot;</span> </li>
<li style="background:#f3f3f3;">                      <span style="color:#ff0000;"> Behaviors</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">AttachedBehavior.IsEnabled</span><span style="color:#0000ff;">=&quot;{</span><span style="color:#a31515;">Binding</span><span style="color:#ff0000;"> IsDragBehaviorEnabled}</span><span style="color:#0000ff;">&quot;</span> </li>
<li>                      <span style="color:#ff0000;"> Behaviors</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">AttachedBehavior.Behavior</span><span style="color:#0000ff;">=&quot;{</span><span style="color:#a31515;">Binding</span><span style="color:#ff0000;"> DragDropBehavior}</span><span style="color:#0000ff;">&quot;</span></li>
<li style="background:#f3f3f3;">                      <span style="color:#ff0000;"> Canvas.Left</span><span style="color:#0000ff;">=&quot;32&quot;</span></li>
<li>                      <span style="color:#ff0000;"> Canvas.Top</span><span style="color:#0000ff;">=&quot;31&quot; /&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<h1>&#160;</h1>
<h1>HelloViewViewModel</h1>
<p>&#160;</p>
<p>And finally the ViewModel that set’s the DragDropBehavior:</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:538f2066-181e-4110-b4fd-63235532c4d3" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;white-space:nowrap;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">HelloViewViewModel</span> : <span style="color:#2b91af;">ViewModelBase</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">IBehavior</span> _dragDropBehavior;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">bool</span> _isDragBehaviorEnabled;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">bool</span> IsDragBehaviorEnabled</li>
<li>        {</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _isDragBehaviorEnabled; }</li>
<li>            <span style="color:#0000ff;">set</span> { _isDragBehaviorEnabled = <span style="color:#0000ff;">value</span>; RaisePropertyChanged(()=&gt; <span style="color:#0000ff;">this</span>.IsDragBehaviorEnabled); }</li>
<li style="background:#f3f3f3;">        }</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">IBehavior</span> DragDropBehavior</li>
<li>        {</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _dragDropBehavior; }</li>
<li>            <span style="color:#0000ff;">set</span> { _dragDropBehavior = <span style="color:#0000ff;">value</span>; RaisePropertyChanged(() =&gt; <span style="color:#0000ff;">this</span>.DragDropBehavior); }</li>
<li style="background:#f3f3f3;">        }</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">RelayCommand</span> ToggleDragDropBehavior { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">public</span> HelloViewViewModel()</li>
<li>        {</li>
<li style="background:#f3f3f3;">            DragDropBehavior = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DragDropBehavior</span>();</li>
<li>            ToggleDragDropBehavior = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">RelayCommand</span>(() =&gt; </li>
<li style="background:#f3f3f3;">            {</li>
<li>                IsDragBehaviorEnabled = !IsDragBehaviorEnabled;</li>
<li style="background:#f3f3f3;">            });</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        }</li>
<li>    }</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>That’s It &#8211; you are done!! Refer DragDropBehavior2 class for implementation using Behavior&lt;T&gt;.</p>
<p><a href="http://dl.dropbox.com/u/7557124/nnish.com/Code/AttachedBehaviorMVVM.zip">Download the Code</a> – Read the Disclaimer of this blog before you work with this code!</p>
<p>/*Nish*/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/240/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/240/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/240/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=240&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2012/04/22/attached-behaviors-mvvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2012/04/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2012/04/attachedbimage_thumb.png" medium="image">
			<media:title type="html">AttachedBImage</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows 8 on VirtualBox&#8211; File Sharing(Guest Additions doesn&#8217;t work)</title>
		<link>http://nnish.com/2012/04/17/windows-8-on-virtualbox-file-sharingguest-additions-doesnt-work/</link>
		<comments>http://nnish.com/2012/04/17/windows-8-on-virtualbox-file-sharingguest-additions-doesnt-work/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 17:55:35 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Windows8]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/?p=231</guid>
		<description><![CDATA[Guest Additions on Virtual Box can be installed by changing compatibility to Windows 7 but that doesn&#8217;t mean it can be made to work. Yeah that’s where I too got stuck and my hunt for a fix to it also stopped when I read this forum. I found few others who have tried complicated file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=231&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Guest Additions on Virtual Box can be installed by changing compatibility to Windows 7 but that doesn&#8217;t mean it can be made to work. Yeah that’s where I too got stuck and my hunt for a fix to it also stopped when I read this <a href="https://forums.virtualbox.org/viewtopic.php?f=6&amp;t=44639">forum</a>. </p>
<p>I found few others who have tried complicated file sharing techniques, for e.g. they&#160; created a secondary virtual hard drive and put files into it. However being working on Windows for more than a decade, I do believe there should be a simple way to achieve it. After all they are two different windows machines on the network. </p>
<p>Well what would you do to access a share drive on another system? <strong>Start-&gt;Run-&gt; and type “\\machine-name\share”</strong> and hit enter?&#160; That wouldn’t work because your host machine name will not be recognized by your virtual machine since they are on a different network group. </p>
<p><strong>Now here is the solution:</strong> Go ahead and figure out the <strong>IP address of your host machine(ipconfig)</strong> and try accessing the share by its IP address instead of the machine name. <strong>That works!</strong></p>
<p>&#160;</p>
<p><a href="http://nnish.files.wordpress.com/2012/04/access.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="Access" border="0" alt="Access" src="http://nnish.files.wordpress.com/2012/04/access_thumb.png?w=599&h=450" width="599" height="450" /></a></p>
<p>Things are simple, we complicate it most of the time.</p>
<p>&#160;</p>
<p>/* Nish */</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=231&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2012/04/17/windows-8-on-virtualbox-file-sharingguest-additions-doesnt-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2012/04/access_thumb.png" medium="image">
			<media:title type="html">Access</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF XML Browser Control</title>
		<link>http://nnish.com/2012/04/12/wpf-xml-browser-control/</link>
		<comments>http://nnish.com/2012/04/12/wpf-xml-browser-control/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 18:07:00 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WebBrowser]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/?p=224</guid>
		<description><![CDATA[Ever wondered how to get a IE like look and feel of the xml in the default WPF web browser control? If your answer is – “Just navigate the Web Browser to the xml path”; You are right! But if you have to navigate to a in-memory xml? Read on to know and apply IE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=224&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how to get a IE like look and feel of the xml in the default WPF web browser control? If your answer is – “Just navigate the Web Browser to the xml path”; You are right! But if you have to navigate to a in-memory xml? Read on to know and apply IE like styling for xml stored in a string variable.</p>
<p>Idea of writing a custom based xml browser control came in because I had a requirement to edit the xml on fly and validate it against a specified schema. User is allowed to edit only the standard xml(compiled as an embedded resource) that the tool provides and not navigate to any path.</p>
<p>This control helps you:</p>
<ol>
<li>Load the xml from the string and apply IE like styling </li>
<li>Edit the xml </li>
<li>Validate the xml against the defined schema </li>
</ol>
<p>Before I go further, here is what you get:</p>
<p><a href="http://nnish.files.wordpress.com/2012/04/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://nnish.files.wordpress.com/2012/04/image_thumb.png?w=600&h=220" width="600" height="220" /></a></p>
<p>The problem with web browser when navigating to a string is that it does not load the style for it. Hence the work around is to transform the xml and navigate to it. To do so you need the Xslt that IE uses. After googling for “xml pretty print”, I finally got one originally written by Jonathan Marsh of Microsoft for IE5 and modified by Steve Muench for conversion to XSLT 1.0 REC.&#160; Copy the xml from <a href="http://www.biglist.com/lists/xsl-list/archives/199907/msg00103.html">here</a>.</p>
<p>And here is the code to transform it:</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ab258395-6637-473f-80cd-3e27a3668201" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;overflow:auto;padding:2px 5px;white-space:nowrap;"> <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> Executes when XmlDoc DP is changed, Loads the xml and tranforms it using XSL provided</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&quot;d&quot;&gt;&lt;/param&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&quot;e&quot;&gt;&lt;/param&gt;</span><br />         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> OnXmlDocChanged(<span style="color:#2b91af;">DependencyObject</span> d, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span> e)<br />         {<br />             <span style="color:#0000ff;">var</span> browserControl = d <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">XmlBrowserControl</span>;<br />             <span style="color:#0000ff;">if</span> (browserControl == <span style="color:#0000ff;">null</span>) <span style="color:#0000ff;">return</span>;<br />             <span style="color:#0000ff;">var</span> xmlString = e.NewValue <span style="color:#0000ff;">as</span> <span style="color:#0000ff;">string</span>;<br />             <br />             <span style="color:#0000ff;">try</span><br />             {</p>
<p>                 <span style="color:#0000ff;">var</span> xmlDocument = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">XmlDocument</span>();</p>
<p>                 <span style="color:#0000ff;">var</span> xmlDocStyled = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">StringBuilder</span>(2500);<br />                 <span style="color:#008000;">// mark of web &#8211; to enable IE to force webpages to run in the security zone of the location the page was saved from</span><br />                 <span style="color:#008000;">// http://msdn.microsoft.com/en-us/library/ms537628(v=vs.85).aspx</span><br />                 xmlDocStyled.Append(<span style="color:#a31515;">&quot;&lt;!&#8211; saved from url=(0014)about:internet &#8211;&gt;&quot;</span>);</p>
<p>                 <span style="color:#0000ff;">var</span> xslt = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">XslCompiledTransform</span>();<br />                 <span style="color:#008000;">//</span><span style="color:#00008b;">TODO: Do not forget to change the namespace, if you move the xsl sheet to your application</span><br />                 <span style="color:#0000ff;">var</span> xsltFileStream =<br />                     <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">XmlBrowserControl</span>).Assembly.GetManifestResourceStream(<br />                         <span style="color:#a31515;">&quot;WPFXmlBrowser.Controls.XmlBrowser.Resources.xml-pretty-print.xsl&quot;</span>);<br />                 <span style="color:#0000ff;">if</span> (xsltFileStream != <span style="color:#0000ff;">null</span>)<br />                 {<br />                     <span style="color:#008000;">//Load the xsltFile</span><br />                     <span style="color:#0000ff;">var</span> xmlReader = <span style="color:#2b91af;">XmlReader</span>.Create(xsltFileStream);<br />                     xslt.Load(xmlReader);<br />                     <span style="color:#0000ff;">var</span> settings = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">XmlWriterSettings</span>();<br />                     <span style="color:#008000;">// writer for transformation</span><br />                     <span style="color:#0000ff;">var</span> writer = <span style="color:#2b91af;">XmlWriter</span>.Create(xmlDocStyled, settings);<br />                     <span style="color:#0000ff;">if</span> (xmlString != <span style="color:#0000ff;">null</span>) xmlDocument.LoadXml(xmlString);<br />                     xslt.Transform(xmlDocument, writer);</p>
<p>                 }</p>
<p>                 browserControl.EditText.Text = xmlString;<br />                 browserControl.WebBrowser.NavigateToString(xmlDocStyled.ToString());<br />                 browserControl.EditButton.Visibility = System.Windows.<span style="color:#2b91af;">Visibility</span>.Visible;<br />                 browserControl.CopyClipButton.Visibility = System.Windows.<span style="color:#2b91af;">Visibility</span>.Visible;<br />             }<br />             <span style="color:#0000ff;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)<br />             {<br />                 browserControl.WebBrowser.NavigateToString(<span style="color:#a31515;">&quot;Unable to parse xml. Correct the following errors: &quot;</span> + ex.Message);<br />             }<br />         }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>XSLT is provided as an embedded resource and it is loaded from the code. If you are moving the xslt to your project, make sure to change the namespace in the calling code.</p>
<p><a href="http://nnish.files.wordpress.com/2012/04/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://nnish.files.wordpress.com/2012/04/image_thumb1.png?w=318&h=293" width="318" height="293" /></a></p>
<p>You can download the code from my share <a href="http://dl.dropbox.com/u/7557124/nnish.com/Code/WPFXmlBrowser.zip">here</a>. This code works on my machine!</p>
<p>Feel free to modify the code, but as usual you don’t get warranty!</p>
<p>/*Nish*/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=224&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2012/04/12/wpf-xml-browser-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2012/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2012/04/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello Windows 8 world&#8211;Installation on a Virtual Machine</title>
		<link>http://nnish.com/2011/09/15/hello-windows-8-worldinstallation-on-a-virtual-machine/</link>
		<comments>http://nnish.com/2011/09/15/hello-windows-8-worldinstallation-on-a-virtual-machine/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 05:50:07 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[VMWare]]></category>
		<category><![CDATA[Windows8]]></category>
		<category><![CDATA[VHD]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/2011/09/15/hello-windows-8-worldinstallation-on-a-virtual-machine/</guid>
		<description><![CDATA[2009 was the year I wrote a post on Installing Windows 7 on VMware, and 2 years later with the same excitement here I am saying Hello to Windows 8. This time I am not elaborating on the installation but yes will share some interesting posts already on it. Few approaches: Installing Windows 8 Developer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=212&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>2009 was the year I wrote a post on <a href="http://nnish.com/2009/07/01/windows-7-on-vmware/">Installing Windows 7 on VMware</a>, and 2 years later with the same excitement here I am saying Hello to Windows 8. This time I am not elaborating on the installation but yes will share some interesting posts already on it.</p>
<p><strong>Few approaches:</strong></p>
<p><a href="http://nnish.in/qDzVUp">Installing Windows 8 Developer Preview in a virtual machine</a>. – <em>I did this, it worked for me!</em></p>
<p><a href="http://nnish.in/qARUzc">Step by step instructions to install Windows 8 successfully on VMWare Workstation 8</a></p>
<p>“<a href="http://www.pitorque.de/MisterGoodcat/post/Installing-Windows-8-Developer-Preview-as-bootable-VHD.aspx">Installing Windows 8 Developer Preview as bootable VHD</a>” – <em>It yields much better performance, this will be my next shot!</em></p>
<p>Before I decided to install it on the Virtual Box, I gave an attempt on the <a href="http://www.microsoft.com/windows/virtual-pc/">Windows Virtual PC</a> which came pre-installed with my OS (if Windows XP Mode is enabled). But then the Win 8 version I wanted to install was a 64 bit developer preview and unfortunately Virtual PC does not support 64bit guest OS. You will get this error “This 64-bit application couldn&#8217;t load because your PC doesn&#8217;t have a 64-bit processor”.</p>
<p>Installation on a VirtualBox was a different experience for me &#8211; <a href="http://en.wikipedia.org/wiki/Blue_Screen_of_Death">BSOD</a>s and Graphical driver crash. <strong>No you may not face</strong> this because unlike me; you would never attempt to run a Virtual PC in parallel with a Virtual Box <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://nnish.files.wordpress.com/2011/09/wlemoticon-smile.png?w=600" alt="Smile" />.</p>
<p><strong>One important thing to do before you install</strong> is to check, if your processor supports Virtualization and enable it in your BIOS. If not you will get this error “Failed to start virtual machine (name of machine) VT-x is not available” when you start the VM.</p>
<p>If you are using an Intel Processor, check its specification at <a href="http://ark.intel.com/">ark.intel.com</a>, Intel Virtualization technology(VT-X) should be supported.</p>
<p><a href="http://nnish.files.wordpress.com/2011/09/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://nnish.files.wordpress.com/2011/09/image_thumb.png?w=587&h=58" alt="image" width="587" height="58" border="0" /></a></p>
<p>By default these features are disabled, so enable these from your BIOS settings.</p>
<p>Go ahead and complete your installation:</p>
<p><a href="http://nnish.files.wordpress.com/2011/09/287664_10150801452540713_520785712_20554375_1592634805_o.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border:0;" title="287664_10150801452540713_520785712_20554375_1592634805_o" src="http://nnish.files.wordpress.com/2011/09/287664_10150801452540713_520785712_20554375_1592634805_o_thumb.jpg?w=586&h=440" alt="287664_10150801452540713_520785712_20554375_1592634805_o" width="586" height="440" border="0" /></a></p>
<p>I must say this before I conclude this post – “<strong>Win 8 without a touch monitor on a VM is just a Win 7 with painful experience</strong>!” If you are a developer and you want your machine to respond as per your original hardware then do a clean install or use a VHD!.</p>
<p>Some interesting links:</p>
<p><a href="http://download.microsoft.com/download/1/E/4/1E455D53-C382-4A39-BA73-55413F183333/Windows_Developer_Preview-Windows8_guide.pdf">Windows Developer Preview Guide</a></p>
<p><a href="http://code.msdn.microsoft.com/windowsapps">Metro Style App Examples</a></p>
<p><a href="http://www.istartedsomething.com/20110914/short-winrt-capabilities-dissected/">WinRT Capabilities</a></p>
<p><em>Note: Please read the disclaimer on my page before you get started.</em></p>
<p>/*Nish*/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=212&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2011/09/15/hello-windows-8-worldinstallation-on-a-virtual-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2011/09/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2011/09/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2011/09/287664_10150801452540713_520785712_20554375_1592634805_o_thumb.jpg" medium="image">
			<media:title type="html">287664_10150801452540713_520785712_20554375_1592634805_o</media:title>
		</media:content>
	</item>
		<item>
		<title>Android WIFI Problem &#8211; Obtaining Address&#8230;</title>
		<link>http://nnish.com/2010/12/05/android-wifi-problem-obtaining-address/</link>
		<comments>http://nnish.com/2010/12/05/android-wifi-problem-obtaining-address/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 17:25:25 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[WIFI]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/2010/12/05/android-wifi-problem-obtaining-address/</guid>
		<description><![CDATA[Ever since I changed my broadband modem, I have been facing issues with my HTC Wildfire connecting to my WIFI router. Every time it connects to my WIFI, it gives a message “Obtaining address..” and its stuck with this message for sometime. Having just a fair knowledge on networking, it took me some steps to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=203&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever since I changed my broadband modem, I have been facing issues with my HTC Wildfire connecting to my WIFI router. Every time it connects to my WIFI, it gives a message “Obtaining address..” and its stuck with this message for sometime. Having just a fair knowledge on networking, it took me some steps to reach to a solution. And here it is… </p>
<p><strong>For some of you it may work by simply restarting your WIFI or by restarting your Android device. If it doesn’t, read on to find out if your problem is similar to mine.</strong></p>
<p>Before I jump into the solution, it is important that you understand my network and my devices. My internet broadband modem and WIFI router are two different entities – meaning my modem does not support WIFI routing, so I had to have a WIFI router separately. </p>
<ol>
<li>Modem – Binatone DT815 ADSL2+ router (supplied by Airtel India)</li>
<li>WIFI Router – Netgear WGR614</li>
<p>From here on for better understanding I will use the term “Modem” to represent my broadband device and “WIFI Router” to represent my WIFI device. Since both the devices are capable of DHCP, I had to disable one to avoid conflicts. I wanted the default gateway to be the modem’s, so I enabled DHCP only on my modem and disabled the other. Modem detects the WIFI router as just another device in its network and not as a router.</ol>
<ol>My IP addresses are configured like this:
<li>Modem – 192.168.1.1</li>
<li>WIFI Router – 192.168.1.2 (Set from router’s LAN Settings)</li>
<li>Other devices which connect, get IPs assigned by the Modem with default gateway as 192.168.1.1</li>
</ol>
<p>Whenever I tried connecting my android device to WIFI, it gets stuck at “Obtaining address..”. I knew the problem lies in address resolution, so it was either my device not accepting the IP issued or the modem not recognizing the android. </p>
<p>I logged into Modem’s configuration and checked the LAN Connection pool summary(this setting displays the connected devices and its MAC addresses). To my surprise I found that my android device was issued an IP which was same as my router (192.168.1.2) and thus the conflict. </p>
<p><strong>There were two ways I could resolve this conflict:</strong></p>
<ol>
<li><strong>Change the WIFI router’s IP (from it’s LAN Settings &#8211; by logging into WIFI configuration)</strong></li>
<li><strong>Use a Static IP Address in your android device.</strong></li>
</ol>
<ol>For some reason point 2 never worked for me; but point 1 did. Hope this helps someone.</ol>
<p>Cheers</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=203&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/12/05/android-wifi-problem-obtaining-address/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>
	</item>
		<item>
		<title>Have an operation to measure? Use Stopwatch()</title>
		<link>http://nnish.com/2010/10/20/have-an-operation-to-measure-use-stopwatch/</link>
		<comments>http://nnish.com/2010/10/20/have-an-operation-to-measure-use-stopwatch/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 01:30:19 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/2010/10/20/have-an-operation-to-measure-use-stopwatch/</guid>
		<description><![CDATA[Quite often we run into situations where we need to measure the elapsed time of a method/operation, and there are number of ways to do it. The simplest way to do is by using a Stopwatch. This class is available under the namespace System.Diagnostics. To show you a demo, I have used a simple app [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=199&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Quite often we run into situations where we need to measure the elapsed time of a method/operation, and there are number of ways to do it. The simplest way to do is by using a <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx" target="_blank">Stopwatch</a>. This class is available under the namespace <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx">System.Diagnostics</a>. </p>
<p>To show you a demo, I have used a simple app which calculates the time taken to load a website on your local machine. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:996868d6-de8a-41c1-a443-a1fc91f57b03" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#0000ff;">namespace</span> Nish.Stopwatch<br /> {<br />     <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Program</span><br />     {<br />         <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Main(<span style="color:#0000ff;">string</span>[] args)<br />         {<br />             <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&quot;WebAddress&gt; &quot;</span>);<br />             <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&quot;Your website took about &quot;</span> + LoadWebsite(<span style="color:#2b91af;">Console</span>.ReadLine()).Seconds + <span style="color:#a31515;">&quot; seconds to load on your machine&quot;</span>);<br />             <span style="color:#2b91af;">Console</span>.ReadLine();<br />         }</p>
<p>         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> Gets the load time of a website</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&quot;websitePath&quot;&gt;</span><span style="color:#008000;">Path in the format: e.g. http://nnish.com </span><span style="color:#808080;">&lt;/param&gt;</span><br />         <span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;returns&gt;</span><span style="color:#008000;">Time taken</span><span style="color:#808080;">&lt;/returns&gt;</span><br />         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">TimeSpan</span> LoadWebsite(<span style="color:#0000ff;">string</span> websitePath)<br />         {<br />             System.Diagnostics.<span style="color:#2b91af;">Stopwatch</span> stpWatch = <span style="color:#0000ff;">new</span> System.Diagnostics.<span style="color:#2b91af;">Stopwatch</span>();<br />             stpWatch.Start();<br />             <span style="color:#2b91af;">HttpWebRequest</span> request = (<span style="color:#2b91af;">HttpWebRequest</span>)<span style="color:#2b91af;">WebRequest</span>.Create(websitePath);</p>
<p>             <span style="color:#008000;">// execute the request</span><br />             <span style="color:#2b91af;">HttpWebResponse</span> response = (<span style="color:#2b91af;">HttpWebResponse</span>)request.GetResponse();</p>
<p>             <span style="color:#008000;">// Read the data in the stream</span><br />             <span style="color:#2b91af;">StreamReader</span> streamReader = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">StreamReader</span>(response.GetResponseStream());<br />             <span style="color:#008000;">// s &#8211; will have your html content, I am not using this for now</span><br />             <span style="color:#0000ff;">string</span> s = streamReader.ReadToEnd();<br />             stpWatch.Stop();<br />             <br />             <span style="color:#0000ff;">return</span> stpWatch.Elapsed;<br />         }<br />     }<br /> }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Time took for my website to load:</p>
<p><a href="http://nnish.files.wordpress.com/2010/10/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://nnish.files.wordpress.com/2010/10/image_thumb.png?w=596&h=98" width="596" height="98" /></a> </p>
<p>Look at the time Google took:</p>
<p><a href="http://nnish.files.wordpress.com/2010/10/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://nnish.files.wordpress.com/2010/10/image_thumb1.png?w=596&h=98" width="596" height="98" /></a> </p>
<p>And now this was out of curiosity:</p>
<p><a href="http://nnish.files.wordpress.com/2010/10/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://nnish.files.wordpress.com/2010/10/image_thumb2.png?w=596&h=98" width="596" height="98" /></a> </p>
<p>Please note: The load time depends on various factors like network speed, server location,&#160; page content etc. So this data should not be treated as accurate. The idea of having this example is to show the usage of Stopwatch and not to determine the speed of the website.</p>
<p>Method <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.start.aspx" target="_blank">Stopwatch.Start()</a> starts the timer, and ticks in parallel until the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.stop.aspx" target="_blank">Stopwatch.Stop()</a> is executed. The start method does not start the elapsed time at 0, if executed again. To set the elapsed time to 0 use either <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.restart.aspx" target="_blank">Stopwatch.Restart()</a> or call <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.reset.aspx" target="_blank">Stopwatch.Reset()</a> before the next start(). So understand that “A <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx">Stopwatch</a> instance calculates and retains the cumulative elapsed time across multiple time intervals, until the instance is reset/restarted.” – MSDN. To start a fresh timer use Stopwatch stopwatch = <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.startnew.aspx" target="_blank">Stopwatch.StartNew()</a> which is a static method.</p>
<p>This comes very handy when you use this for all your performance monitoring or benchmarking on/the your operations. </p>
<p>Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=199&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/10/20/have-an-operation-to-measure-use-stopwatch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2010/10/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2010/10/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2010/10/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Long time since I blogged!</title>
		<link>http://nnish.com/2010/10/20/long-time-since-i-blogged/</link>
		<comments>http://nnish.com/2010/10/20/long-time-since-i-blogged/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 01:28:02 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">https://nnish.wordpress.com/2010/10/20/log-time-since-i-blogged/</guid>
		<description><![CDATA[No laziness is not the only reason why I skipped blogging for months together. I was on a complete learning mode, when I say learning its not just the technical stuffs I am talking about. I was involved in various activities of life, which demanded a lot of my personal time. A lot of activities [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=192&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>No laziness is not the only reason why I skipped blogging for months together. I was on a complete learning mode, when I say learning its not just the technical stuffs I am talking about. I was involved in various activities of life, which demanded a lot of my personal time. A lot of activities which were completely new to me, and had no clue on how to go about it. I am not completely done with it (that said there is no definite time frame on blogging), but have decided to pull out some of my time. My passion for technology and photography are in my breath and that keeps me alive, but off late I realized it wasn’t enough! probably I need some food to survive. And that is something which I will let you know in years to come!</p>
<p>My transition from an entrepreneur to a full time employee was a tough decision, but have to do that to sustain and to overcome the loses! Am I complaining? No I am lucky enough in doing something what I always wanted to do and that is programming! The point is having bitten by the entrepreneur bug in some time of my life, has not let me sleep peaceful. Regaining those momentum and going forward in that direction is even more riskier until I have some concrete things planned. </p>
<p>Other than the learning of life I had couple of new learning which were technical and they were completely new from my field of work. But it was necessary to keep the momentum on. Oh did I say I have some concrete plans? No not yet!</p>
<p>Sometimes taking a right decision is far more easier than making your decision right!</p>
<p>To restart blogging, I am initiating a simple technical post which is coming up next!</p>
<p>Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=192&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/10/20/long-time-since-i-blogged/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing WPF controls on a non UI Thread</title>
		<link>http://nnish.com/2010/03/14/accessing-wpf-controls-on-a-non-ui-thread/</link>
		<comments>http://nnish.com/2010/03/14/accessing-wpf-controls-on-a-non-ui-thread/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 13:41:42 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Dispatcher]]></category>
		<category><![CDATA[DispatcherObject]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[WPF Controls]]></category>

		<guid isPermaLink="false">http://nnish.wordpress.com/2010/03/14/accessing-wpf-controls-on-a-non-ui-thread/</guid>
		<description><![CDATA[I am sure most of you would have run into this issue before. When you try to access a WPF control on a different thread other than your regular UI thread you get a runtime exception “The calling thread cannot access this object because a different thread owns it.”. To understand why this happens, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=190&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am sure most of you would have run into this issue before. When you try to access a WPF control on a different thread other than your regular UI thread you get a runtime exception “<em>The calling thread cannot access this object because a different thread owns it.”.</em> To understand why this happens, it is important to know that WPF applications run on two different threads – one for rendering the controls and the other to manage the user interface. The rendering thread runs in the background and the thread which is visible for us to work on is the UI thread. And hence most of the objects are tied to the UI thread and this is known as thread affinity. Thread affinity is handled by the Dispatcher. Each user interface related work item is channeled through the Dispatcher class, that means every work item is queued by the UI thread in an object called <strong>Dispatcher</strong>. Dispatcher runs the work items on priority basis. Supporting work item prioritization allow WPF to work on a an item for more time and hence more time is consumed on the UI thread. UI thread will have at least one Dispatcher, and each Dispatcher can execute work items in exactly one thread. So it is important to release the work item from the thread as fast as possible so as to increase the UI responsiveness.&#160; To keep the work item small,&#160; I spawned newer threads and executed the discrete blocks of code on these threads. This is exactly where I ran into the exception stated above (when I tried to access the&#160; WPF control).</p>
<p><strong>So here is how I got the exception</strong>:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cdef67f3-5b23-4eb3-b641-36d7e733f1ae" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> myButton_Click(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)<br /> {<br />     <span style="color:#2b91af;">Thread</span> t = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Thread</span>(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ThreadStart</span>(<br />         <span style="color:#0000ff;">delegate</span> <br />         {<br />             <span style="color:#008000;">//accessing the TextBlock.Text on a different thread &#8211; **incorrect**</span><br />             myText.Text = <span style="color:#a31515;">&quot;HI&quot;</span>; <br />         }<br />         ));<br />     t.Start();<br /> }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p><strong>So how to get rid of this?</strong></p>
<p>Now we know why a background running thread cannot access the UI thread. To get rid of this problem it is pretty simple – “Just ask the UI thread to do it for you”. Yes the background thread can request the UI thread to update the control properties on behalf of it. This is achieved by calling the <strong>Invoke</strong> or the <strong>BeginInvoke</strong> method of the <strong>DispatcherObject</strong> class. This will register the work items to the Dispatcher. Invoke is a synchronous call – that is, it doesn’t return until the UI thread actually finishes executing the delegate. BeginInvoke is asynchronous and returns immediately. So as stated above Dispatcher orders work items by priority and hence you can pass the priority using <strong>DispatcherPriority</strong> enumerator while registering the work item to Dispatcher.&#160; <br />So here is the code below which solved my problem:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9f025689-2611-41f8-95f7-bb2c16701f16" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> myButton_Click(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)<br /> {<br />     <span style="color:#2b91af;">Thread</span> t = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Thread</span>(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ThreadStart</span>(<br />         <span style="color:#0000ff;">delegate</span> <br />         {<br />             Dispatcher.Invoke(<span style="color:#2b91af;">DispatcherPriority</span>.Normal, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">TextBlock</span>&gt;(SetValue), myText);<br />         }<br />         ));<br />     t.Start();<br /> }</p>
<p> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> SetValue(<span style="color:#2b91af;">TextBlock</span> txt)<br /> {<br />     txt.Text = <span style="color:#a31515;">&quot;HI&quot;</span>;<br /> }</div>
</p></div>
</p></div>
<p><strong></strong></p>
<p>In the Dispatcher.Invoke() method used above takes three parameters – DispatcherPriority Enum, Delegate to execute the code and the parameter object. I used the Action&lt;T&gt; generic type to pass the control to the method to set its property. </p>
<p>It is suggested to use the setting of the control properties in the UI thread itself, and only move those code like say calculations to another thread. This will provide a better code maintenance. </p>
<p>However in the above example we do not improve the UI responsiveness, as the Invoke() method is called synchronously. Instead use BeginInvoke() method. My intention was to give an insight of the exception – why, and how to deal with it. If you need details on writing better responsive applications refer <a href="http://msdn.microsoft.com/en-us/magazine/cc163328.aspx" target="_blank">Shawn Wildermuth&#8217;s article</a></p>
<p>Wow another weekend in research -Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=190&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/03/14/accessing-wpf-controls-on-a-non-ui-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>
	</item>
		<item>
		<title>Success in entrepreneurship is for the one who is prepared</title>
		<link>http://nnish.com/2010/01/19/success-in-entrepreneurship-is-for-the-one-who-is-prepared/</link>
		<comments>http://nnish.com/2010/01/19/success-in-entrepreneurship-is-for-the-one-who-is-prepared/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 10:46:17 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[Entrepreneurship]]></category>

		<guid isPermaLink="false">http://nnish.com/?p=172</guid>
		<description><![CDATA[Everyone say &#8220;Entrepreneurship isn&#8217;t easy and not meant for all&#8221;. As an experienced kid I do agree. But why isn&#8217;t it easy for all? When college drop outs like Bill Gates, Steve Jobs and Mark Zuckerberg can do it then why can&#8217;t others? I looked back to see what went wrong in my case. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=172&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Everyone say &#8220;Entrepreneurship isn&#8217;t easy and not meant for all&#8221;. As an experienced kid I do agree. But why isn&#8217;t it easy for all? When college drop outs like Bill Gates, Steve Jobs and Mark Zuckerberg can do it then why can&#8217;t others? I looked back to see what went wrong in my case. I am writing this down so that, I don&#8217;t forget these in my next venture. If this helps you do let me know.</p>
<p><strong>Have A Great Idea, But Sellable &#8211; </strong><br />
Just because you have a great idea, it doesn&#8217;t mean that you have customers for it.It is important to have a market. Identify the need, make sure your solution is unique and deliver with quality. </p>
<p><strong>Have A Vision -</strong><br />
Vision is the key. If you have an idea and a market you are sure shot to go. But will you sustain? Can you resist the change? Vision is not just a statement you need to add it to your about us page. It should be the one which you strictly follow at every stage. Have milestones and look back if you are aligned to the vision.Make sure every one in the company values the vision and follows it. Write down your vision on the paper and put it into a the board discussion. Remember how Microsoft is committed to its vision &#8220;Computer on every desk and in every home&#8221;. Today almost every one has a computer which is personal and running a Windows in it.</p>
<p><strong>Choose Right Partners -</strong><br />
Your best friend is not always a right business partner for you. Because you care for your relationship you shouldn&#8217;t bring him/her into your business- That&#8217;s why they say &#8220;Mind Your Own Business&#8221;. Money plays a major role in business and but in relationships it is negative. So if you care for them then DO NOT. Your partner is one who stays by you during success as well as failure. Usually it happens the other way when you have your friend in business &#8211; He stays with you during success but blames you when you fail. Your partner should think like you, have passion like yours, should be committed like you and should have his/her own capability to make things right. Things fall into place faster when you have partners in different domains like marketing, technology, human resource etc. As they say the Lions, Tigers and other animals constitute a Jungle <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Plan Your Capital, Have A Business Plan -</strong><br />
$$$$Money$$$$ Where is the money to invest? What if i loose? I am a family man. The fear &#8211; setback. <em>&#8220;Money is everything&#8221;</em> Money is not everything but money is needed for everything. Its not right to believe that only a rich kid can do a business. Anyone with a smart business plan can do. A business plan is a written description of your business&#8217;s future. It should have key inputs like:</p>
<p>   1. Executive summary<br />
   2. Business description<br />
   3. Market strategies<br />
   4. Competitive analysis<br />
   5. Design and development plan<br />
   6. Operations and management plan<br />
   7. Financial factors<br />
*source: <a href="http://www.entrepreneur.com/startingabusiness/businessplans/article38290.html">entrepreneur.com</a><br />
If you have the fear of investing but you believe in your idea you still can do a great business. I agree that you cannot bring in huge capital into your business, instead approach a venture capitalist with your business plan. Convince him on the Return On Investment(ROI), if it interests him; he will help.  VCs just eat up your stake because they are the risk takers. Don&#8217;t be greedy just sell your idea and give returns. </p>
<p><strong>Hire Smart People -</strong><br />
Hire smart people on board and give them your best &#8211; the Google way. You should have managers  who understand your business, maintain business secrets and take right decisions for you. Do not get involved in micromanagement it spoils everything. If you have hired a smart guy, you should leave the decision to him. Make them feel special and motivated at every stage. They are not just your employees, they are the people who are committed to you and the company. They are the reason for your success and you are the reason for the failure.</p>
<p><strong>Have A Process -</strong><br />
You need not be a CMM level company to have a process. If you define a process now, you don&#8217;t have to repent later. Your process need not be complicated, but simple enough to take care of everyday activity. In your process make sure you keep milestones and measure your progress.</p>
<p><strong>Change is Constant</strong><br />
Keep changing with times. No business can last long everything has a saturation. Identify the change early and get ready for the future. Once you have  the idea which is already in the market, a great vision, hired smart people, and put a process in place then whats your job? &#8211; Smell the future, plan, and get ready!</p>
<p>These are just few of the points I remembered when I looked back at my failure. May be this is just right to my situation. Let me know if you guys have some other key points that I should keep in mind.</p>
<p>Some resources:<br />
<a href="http://gigaom.com/2010/01/17/5-myths-that-can-kill-a-startup/">5 Myths That Can Kill a Start-Up</a><br />
<a href="http://www.entrepreneur.com/startingabusiness/">Entrepreneur</a></p>
<p>Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=172&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/01/19/success-in-entrepreneurship-is-for-the-one-who-is-prepared/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>
	</item>
		<item>
		<title>Animated Gif in WPF using Windows Forms Control</title>
		<link>http://nnish.com/2010/01/11/animated-gif-in-wpf-using-windows-forms-control/</link>
		<comments>http://nnish.com/2010/01/11/animated-gif-in-wpf-using-windows-forms-control/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 16:48:22 +0000</pubDate>
		<dc:creator>nnish</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Animated Gif in WPF]]></category>
		<category><![CDATA[Win Forms Control in WPF]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[WindowsFormsHost]]></category>
		<category><![CDATA[WindowsFormsIntegration]]></category>

		<guid isPermaLink="false">http://nnish.wordpress.com/2010/01/11/animated-gif-in-wpf-using-windows-forms-control/</guid>
		<description><![CDATA[Loading an animated gif into WPF has been a challenge since the version 1 release. WPF does not support loading an animated gifs directly into an declarative &#60;Image&#62; or by code, and hence developers have come out with various workarounds. Some use a raw technique – writing few lines of code which extracts the frames [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=171&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Loading an animated gif into WPF has been a challenge since the version 1 release. WPF does not support loading an animated gifs directly into an declarative &lt;Image&gt; or by code, and hence developers have come out with various workarounds. Some use a raw technique – writing few lines of code which extracts the frames of the GIF and animate them.&#160; One other way to do is using the &lt;MediaElement&gt; FrameworkElement which is in the namespace System.Windows.Controls. &lt;MediaElement&gt; wraps the MediaPlayer class for declarative use and hence it supports both audio and video files. Using MediaElement you can load the animated gif the following way:</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:29b763d5-a412-449d-bf99-cbb3ac6b364b" class="wlWriterEditableSmartContent">
<div class="le-pavsc-container">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">MediaElement</span><span style="color:#ff0000;"> Source</span><span style="color:#0000ff;">=&quot;file://D:&#92;anim.gif&quot;/&gt;</span></div>
</p></div>
</p></div>
</p>
<p>Remember it is important to use “file://” and an absolute path for loading the gif. So you cannot embed the image to a resource file and now you know one of the limitations of it. Every approach does have advantages and limitations of its own, its important to use the right approach based on the project needs.</p>
<p>Another possible way is by making the working Jack do the trick – Yeah I meant lets go back to Win Forms picture box to do the <em>magic</em>. We know PictureBox seamlessly loaded the animated gifs in Win Form days. Wait a minute did I say lets change the project from WPF to Win Forms? No I didn’t. What I said is lets integrate the PictureBox alone to the WPF project. To use the right word, I should say that we need to <strong>host</strong> the Windows Forms Control in WPF. To host a Windows Forms Control you need to make use of the class <strong>WindowsFormsHost</strong> which appears in the <strong>System.Windows.Forms.Integration</strong> namespace in assembly <strong>WindowsFormsIntegration.dll</strong>.</p>
<p>Lets get to the code. The first step to do is add a reference to<strong> System.Windows.Forms.dll</strong> and <strong>WindowsFormsIntegration.dll</strong> to your WPF based project.    </p>
<p><a href="http://nnish.files.wordpress.com/2010/01/references.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="References" border="0" alt="References" src="http://nnish.files.wordpress.com/2010/01/references_thumb.png?w=242&h=242" width="242" height="242" /></a> </p>
<p>Add the following namespaces to your XAML Code.</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:76181bde-473b-4768-ae7d-6632aa168afa" class="wlWriterEditableSmartContent">
<div class="le-pavsc-container">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Window</span><span style="color:#ff0000;"> x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Class</span><span style="color:#0000ff;">=&quot;WpfApplication2.Window1&quot;</span><br /> &#160;&#160;&#160;<span style="color:#ff0000;"> xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">wfi</span><span style="color:#0000ff;">=&quot;clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration&quot;</span> <br /> &#160;&#160;&#160;<span style="color:#ff0000;"> xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">winForms</span><span style="color:#0000ff;">=&quot;clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms&quot;</span></div>
</p></div>
</p></div>
</p>
<p>Now you can host the PictureBox inside the WindowsFormsHost and set its Name.</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ad2dcd5-8917-498c-8e0e-00f4a374febd" class="wlWriterEditableSmartContent">
<div class="le-pavsc-container">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#a31515;">&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Grid</span><span style="color:#0000ff;">&gt;</span><br /> <span style="color:#a31515;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">wfi</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">WindowsFormsHost</span><span style="color:#0000ff;">&gt;</span><br /> <span style="color:#a31515;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">winForms</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">PictureBox</span><span style="color:#ff0000;"> x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&quot;pictureBoxLoading&quot;&gt;</span><br /> <span style="color:#a31515;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">winForms</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">PictureBox</span><span style="color:#0000ff;">&gt;</span><br /> <span style="color:#a31515;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">wfi</span><span style="color:#0000ff;">:</span><span style="color:#a31515;">WindowsFormsHost</span><span style="color:#0000ff;">&gt;</span><br /> <span style="color:#a31515;">&#160;&#160;&#160;&#160;</span><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">Grid</span><span style="color:#0000ff;">&gt;</span></div>
</p></div>
</p></div>
</p>
<p>In your code behind(Window1.xaml.cs), add this code to the Window_Loaded Event:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3ba14803-ab7f-4879-8ce0-8ddb348fe9bc" class="wlWriterEditableSmartContent">
<div class="le-pavsc-container">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Window_Loaded(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)<br /> &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{<br /> &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">this</span>.pictureBoxLoading.Image = System.Drawing.<span style="color:#2b91af;">Image</span>.FromFile(<span style="color:#a31515;">&quot;anim.gif&quot;</span>); ;<br /> &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</div>
</p></div>
</p></div>
<p>Key points before execution:</p>
<ol>
<li>Make sure you provide the right path to load the image</li>
<li>You can also load it from a resource file.</li>
</ol>
<p>Since Windows Forms has several interesting built in controls that WPF lacks, using this technique you can make your favorite Windows Forms control work in WPF.</p>
<p>Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nnish.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nnish.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nnish.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nnish.com&#038;blog=8282319&#038;post=171&#038;subd=nnish&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nnish.com/2010/01/11/animated-gif-in-wpf-using-windows-forms-control/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3fd0a78fbb13bf437440e7c7ce21ef9f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nnish</media:title>
		</media:content>

		<media:content url="http://nnish.files.wordpress.com/2010/01/references_thumb.png" medium="image">
			<media:title type="html">References</media:title>
		</media:content>
	</item>
	</channel>
</rss>
