<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>MICHEL'S WEBLOG - .NET</title>
    <link>http://www.michelvandervlugt.net/</link>
    <description>MICHELVANDERVLUGT.NET</description>
    <language>en-us</language>
    <copyright>Michel van der Vlugt</copyright>
    <lastBuildDate>Fri, 20 Aug 2010 12:33:32 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>blog@michelvandervlugt.net</managingEditor>
    <webMaster>blog@michelvandervlugt.net</webMaster>
    <item>
      <trackback:ping>http://www.michelvandervlugt.net/Trackback.aspx?guid=9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b</trackback:ping>
      <pingback:server>http://www.michelvandervlugt.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.michelvandervlugt.net/PermaLink,guid,9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b.aspx</pingback:target>
      <dc:creator>Michel van der Vlugt</dc:creator>
      <wfw:comment>http://www.michelvandervlugt.net/CommentView,guid,9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b.aspx</wfw:comment>
      <wfw:commentRss>http://www.michelvandervlugt.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WindowsAzureTableStorageinthedevelopment_A7CA/image_2.png">
            <img style="border-right-width: 0px; margin: 0px 0px 0px 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WindowsAzureTableStorageinthedevelopment_A7CA/image_thumb.png" width="304" height="304" />
          </a>
        </p>
        <p>
In addition to my previous post <a href="http://www.michelvandervlugt.net/PermaLink,guid,d7f7cf98-fd3d-4830-9620-aa5f9644639f.aspx" target="_blank">Windows
Azure Table Storage in the development environment</a> I’ve created a demo application
in which responsibilities are distributed over classes in a way that hides the implementation
details of Azure’s table storage.
</p>
        <p>
The application is pretty simple, a one page ASP.NET app in which you can add/edit
movies. The movies are displayed on the same page in a GridView.
</p>
        <p>
          <strong>Movie model</strong>
          <br />
The model has changed a bit. The RowKey is now filled with a GUID (instead of the
title) to uniquely identify a movie in the table. The title now has a dedicated property.
The PartitionKey remains the movie category as this helps Azure to partition the data
over multiple servers if the load gets too heavy.
</p>
        <p>
          <strong>StorageContext</strong>
          <br />
        </p>
        <p>
The StorageContext is the actual entry point to the data. It inherits from TableServiceContext
and provides a property Movies that returns an IQueryable of type Movie, which can
be used to query the data from storage. It also provides an AddMovie method to avoid
exposure of the table name that is required for using TableServiceContext.AddObject.
</p>
        <p>
To create a new StorageContext the StorageContextFactory can be used, which hides
the creation/initialization of the StorageContext.
</p>
        <p>
          <strong>MovieRepository</strong>
          <br />
The repository is used to access the data from the application. Creation of a MovieRepository
requires a context that implements IStorageContext (e.g. StorageContext), which can
be obtained by the StorageContextFactory. The reason for using an interface to the
context is to be able to replace the context by some other implementation, for example
in case of a non-Azure application or in case of unit-testing.
</p>
        <p>
          <strong>Example</strong>
        </p>
        <p>
        </p>
        <div class="csharpcode">
          <pre>
            <span class="lnum"> 1: </span>MovieRepository repository
= </pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">new</span> MovieRepository(StorageContextFactory.GetContext());</pre>
          <pre>
            <span class="lnum"> 3: </span> </pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="rem">// Get all movies</span>
          </pre>
          <pre>
            <span class="lnum"> 5: </span>IEnumerable&lt;Movie&gt; allMovies = repository.GetAll();</pre>
          <pre>
            <span class="lnum"> 6: </span> </pre>
          <pre>
            <span class="lnum"> 7: </span>
            <span class="rem">// Get a single movie</span>
          </pre>
          <pre>
            <span class="lnum"> 8: </span>Movie movie = repository.GetById(key);</pre>
          <pre>
            <span class="lnum"> 9: </span> </pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="rem">// Add a new movie</span>
          </pre>
          <pre>
            <span class="lnum"> 11: </span>Movie newMovie = MovieFactory.Create();</pre>
          <pre>
            <span class="lnum"> 12: </span>newMovie.PartitionKey = <span class="str">"Action"</span>;</pre>
          <pre>
            <span class="lnum"> 13: </span>newMovie.Title = <span class="str">"An action
movie!"</span>;</pre>
          <pre>
            <span class="lnum"> 14: </span>repository.Add(newMovie);</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <br />
A few notes: 
<p></p><ul><li>
A MovieFactory is used to create a new Movie. In this factory an instance of a Movie
is created and the RowKey property is populated with a new GUID. There are several
alternatives but in this way you avoid unnecessary creation of GUIDs when objects
are created by the context (in case you initialize in the Movie’s constructor), and
you avoid the need for an initialization method that can potentially be forgotten
to invoke.</li><li>
The Add and Update methods on repository directly save to the storage. This might
not be what you want in other apps, but for this example (with only one update in
each postback) it is good enough.</li></ul><p>
The source of the example can be downloaded <a href="http://michelvandervlugt.net/content/binary/CloudServiceDemo.zip" target="_blank">here</a>.
</p><img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b" /></body>
      <title>Windows Azure Table Storage in the development environment, part II</title>
      <guid isPermaLink="false">http://www.michelvandervlugt.net/PermaLink,guid,9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b.aspx</guid>
      <link>http://www.michelvandervlugt.net/PermaLink,guid,9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b.aspx</link>
      <pubDate>Fri, 20 Aug 2010 12:33:32 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WindowsAzureTableStorageinthedevelopment_A7CA/image_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 0px 0px 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WindowsAzureTableStorageinthedevelopment_A7CA/image_thumb.png" width="304" height="304"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In addition to my previous post &lt;a href="http://www.michelvandervlugt.net/PermaLink,guid,d7f7cf98-fd3d-4830-9620-aa5f9644639f.aspx" target="_blank"&gt;Windows
Azure Table Storage in the development environment&lt;/a&gt; I’ve created a demo application
in which responsibilities are distributed over classes in a way that hides the implementation
details of Azure’s table storage.
&lt;/p&gt;
&lt;p&gt;
The application is pretty simple, a one page ASP.NET app in which you can add/edit
movies. The movies are displayed on the same page in a GridView.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Movie model&lt;/strong&gt;
&lt;br&gt;
The model has changed a bit. The RowKey is now filled with a GUID (instead of the
title) to uniquely identify a movie in the table. The title now has a dedicated property.
The PartitionKey remains the movie category as this helps Azure to partition the data
over multiple servers if the load gets too heavy.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;StorageContext&lt;/strong&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
The StorageContext is the actual entry point to the data. It inherits from TableServiceContext
and provides a property Movies that returns an IQueryable of type Movie, which can
be used to query the data from storage. It also provides an AddMovie method to avoid
exposure of the table name that is required for using TableServiceContext.AddObject.
&lt;/p&gt;
&lt;p&gt;
To create a new StorageContext the StorageContextFactory can be used, which hides
the creation/initialization of the StorageContext.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;MovieRepository&lt;/strong&gt;
&lt;br&gt;
The repository is used to access the data from the application. Creation of a MovieRepository
requires a context that implements IStorageContext (e.g. StorageContext), which can
be obtained by the StorageContextFactory. The reason for using an interface to the
context is to be able to replace the context by some other implementation, for example
in case of a non-Azure application or in case of unit-testing.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;MovieRepository repository
= &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; MovieRepository(StorageContextFactory.GetContext());&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;&lt;span class="rem"&gt;// Get all movies&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt;IEnumerable&amp;lt;Movie&amp;gt; allMovies = repository.GetAll();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&lt;span class="rem"&gt;// Get a single movie&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;Movie movie = repository.GetById(key);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;&lt;span class="rem"&gt;// Add a new movie&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt;Movie newMovie = MovieFactory.Create();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt;newMovie.PartitionKey = &lt;span class="str"&gt;"Action"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt;newMovie.Title = &lt;span class="str"&gt;"An action
movie!"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt;repository.Add(newMovie);&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;br&gt;
A few notes: 
&lt;p&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A MovieFactory is used to create a new Movie. In this factory an instance of a Movie
is created and the RowKey property is populated with a new GUID. There are several
alternatives but in this way you avoid unnecessary creation of GUIDs when objects
are created by the context (in case you initialize in the Movie’s constructor), and
you avoid the need for an initialization method that can potentially be forgotten
to invoke.&lt;/li&gt;
&lt;li&gt;
The Add and Update methods on repository directly save to the storage. This might
not be what you want in other apps, but for this example (with only one update in
each postback) it is good enough.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The source of the example can be downloaded &lt;a href="http://michelvandervlugt.net/content/binary/CloudServiceDemo.zip" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b" /&gt;</description>
      <comments>http://www.michelvandervlugt.net/CommentView,guid,9ecd462b-ee39-4f6a-bc61-72e66fb5ef6b.aspx</comments>
      <category>.NET;Windows Azure</category>
    </item>
    <item>
      <trackback:ping>http://www.michelvandervlugt.net/Trackback.aspx?guid=dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b</trackback:ping>
      <pingback:server>http://www.michelvandervlugt.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.michelvandervlugt.net/PermaLink,guid,dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b.aspx</pingback:target>
      <dc:creator>Michel van der Vlugt</dc:creator>
      <wfw:comment>http://www.michelvandervlugt.net/CommentView,guid,dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b.aspx</wfw:comment>
      <wfw:commentRss>http://www.michelvandervlugt.net/SyndicationService.asmx/GetEntryCommentsRss?guid=dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/Silverlight1.0ReleaseCandidate_B63D/SilverlightExpired.png" atomicselection="true">
          <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="88" alt="SilverlightExpired" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/Silverlight1.0ReleaseCandidate_B63D/SilverlightExpired_thumb.png" width="240" align="right" border="0" />
        </a>
        <p>
When opening my blog today I received an error message indicating that the WPF/E (Silverlight)
version installed on my system is out of date. The result of the error is that my <a href="http://www.michelvandervlugt.net/PermaLink,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx" target="_blank">post
about Silverlight</a> isn't working anymore (in fact, the area of the app is
not refreshed and shows bits and pieces of other content on the page).
</p>
        <p>
The new 1.0 RC (javascript) and 1.1 Alpha Refresh (javascript and managed code) versions
can be downloaded from <a href="http://www.microsoft.com/silverlight/downloads.aspx" target="_blank">here</a>.
However, that doesn't help with my example, although the 'Get Microsoft Silverlight'
image is back. 
</p>
        <p>
The key to get it working again is to update the project with the new 'Silverlight Tools Alpha
Refresh for Visual Studio', which is for VS2008 Beta II. But than I
ran into error 'AG_E_INVALID_ARGUMENT 2210 Error' when the app tried to load my button
(which is in another assembly). To solve this problem you have to make sure that the
build action of the XAML control is set as 'Embedded Resource', which is described
in a blog post of <a href="http://blog.wekeroad.com/archive/2007/07/09/silverlight-how-to-avoid-the-dreaded-ag_e_invalid_argument-2210-error.aspx" target="_blank">Rob
Conery</a>.
</p>
        <p>
So the browser requires you to upgrade the client machine, but the software isn't
backwards compatible. I guess you shouldn't write software with beta's if you don't
want this to happen...
</p>
        <img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b" />
      </body>
      <title>Silverlight 1.0 RC and 1.1 Alpha Refresh</title>
      <guid isPermaLink="false">http://www.michelvandervlugt.net/PermaLink,guid,dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b.aspx</guid>
      <link>http://www.michelvandervlugt.net/PermaLink,guid,dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b.aspx</link>
      <pubDate>Sun, 05 Aug 2007 14:39:23 GMT</pubDate>
      <description>&lt;a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/Silverlight1.0ReleaseCandidate_B63D/SilverlightExpired.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="88" alt="SilverlightExpired" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/Silverlight1.0ReleaseCandidate_B63D/SilverlightExpired_thumb.png" width="240" align="right" border="0"&gt;&lt;/a&gt; 
&lt;p&gt;
When opening my blog today I received an error message indicating that the WPF/E (Silverlight)
version installed on my system is out of date. The result of the error is that my &lt;a href="http://www.michelvandervlugt.net/PermaLink,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx" target="_blank"&gt;post
about Silverlight&lt;/a&gt; isn't working anymore (in fact,&amp;nbsp;the&amp;nbsp;area of the app&amp;nbsp;is
not refreshed and shows bits and pieces of other content on the page).
&lt;/p&gt;
&lt;p&gt;
The new 1.0 RC (javascript) and 1.1 Alpha Refresh (javascript and managed code) versions
can be downloaded from &lt;a href="http://www.microsoft.com/silverlight/downloads.aspx" target="_blank"&gt;here&lt;/a&gt;.
However, that doesn't help with my example, although the 'Get Microsoft Silverlight'
image is back. 
&lt;/p&gt;
&lt;p&gt;
The key to get it working again is to update the project with the new 'Silverlight&amp;nbsp;Tools&amp;nbsp;Alpha
Refresh for&amp;nbsp;Visual Studio', which is for VS2008&amp;nbsp;Beta II.&amp;nbsp;But than I
ran into error 'AG_E_INVALID_ARGUMENT 2210 Error' when the app tried to load my button
(which is in another assembly). To solve this problem you have to make sure that the
build action of the XAML control is set as 'Embedded Resource', which is described
in a blog post of &lt;a href="http://blog.wekeroad.com/archive/2007/07/09/silverlight-how-to-avoid-the-dreaded-ag_e_invalid_argument-2210-error.aspx" target="_blank"&gt;Rob
Conery&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
So the browser requires you to upgrade the client machine, but&amp;nbsp;the software&amp;nbsp;isn't
backwards compatible. I guess you shouldn't write software with beta's if you don't
want this to happen...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b" /&gt;</description>
      <comments>http://www.michelvandervlugt.net/CommentView,guid,dcd1c9a1-c18d-4ec1-97fa-330ecce3f72b.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.michelvandervlugt.net/Trackback.aspx?guid=6187afea-da04-4b89-bce2-997bc906c990</trackback:ping>
      <pingback:server>http://www.michelvandervlugt.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.michelvandervlugt.net/PermaLink,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx</pingback:target>
      <dc:creator>Michel van der Vlugt</dc:creator>
      <wfw:comment>http://www.michelvandervlugt.net/CommentView,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx</wfw:comment>
      <wfw:commentRss>http://www.michelvandervlugt.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6187afea-da04-4b89-bce2-997bc906c990</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p align="left">
This blog post is about how to develop a small <a href="http://silverlight.net/" target="_blank">Silverlight</a> (the
new MS plug-in for Rich Interactive Applications (RIAs) on the web) application
and get it  running inside this post. The demo app is quite simple, it has a
button that pop ups the Silverlight logo when it is pushed.
</p>
        <p>
          <i>Install development environment</i>
        </p>
        <p>
For development of Silverlight apps the Orcas edition of VS is required plus some
additional Silverlight packages, which can be downloaded from the <a href="http://silverlight.net/GetStarted/" target="_blank">Silverlight
web site</a>: the runtime 1.1 alpha, development tools for VS Orcas and the SDK for
the necessary documentation and samples. 
</p>
        <p>
  
</p>
        <p>
Using one of the Expression designer tools is optional but if you want to some fancy
design stuff a designer is really a must. For this project I used Expression Blend
2 May Preview as the older version doesn't support Silverlight. 
</p>
        <p>
          <i>Design with Expression Blend</i>
        </p>
        <p>
To get to know a bit about Silverlight and the graphical design possibilities using
Expression Blend I used the great tutorials of <a href="http://www.nibblestutorials.net/" target="_blank">nibbles
tutorials</a>. Playing with these tutorials gives you a great insight in using Blend
to create graphical assets and use them in you app. 
</p>
        <p>
  
</p>
        <p>
For this applications I've created the round button as a user control in a separate
assembly. By adding some animations the button changes color when the mouse enters,
and transforms a little smaller when you click it to create a button down
effect. The rest of the app, including an animation to pop up the picture, is
designed on the page.xaml, which is generated when you create a Silverlight app in
Visual Studio. To use the button (from the separate assembly) on the page you
have to define a namespace in the main canvas of the page.xaml to include the
dll:
</p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:500c31b3-df4c-40ce-974b-d7cf43a4cc18" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #000000; ">&lt;</span>
              <span style="color: #000000; ">Canvas
xmlns</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">http://schemas.microsoft.com/client/2007</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; "> xmlns:x</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">http://schemas.microsoft.com/winfx/2006/xaml</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; "> xmlns:myctrl</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">clr-namespace:SilverlightDemoClasslib;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #000000; "> assembly</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">ClientBin</span>
              <span style="color: #000000; ">/</span>
              <span style="color: #000000; ">SilverlightDemoClasslib.dll</span>
              <span style="color: #000000; ">" </span>
              <span style="color: #000000; "> ... </span>
              <span style="color: #000000; ">&gt;</span>
            </div>
          </pre>
        </div>
        <p>
Now you can add the button by including the namespace prefix:
</p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b4df3105-a1a7-4ee6-acf8-626c15d9a1bc" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #000000; ">&lt;</span>
              <span style="color: #000000; ">Canvas
x:Name</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">buttonCanvas</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; "> Canvas.Left</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">15</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; "> Canvas.Top</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">55</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #000000; ">&lt;</span>
              <span style="color: #000000; ">myctrl:SilverPlayButton
x:Name</span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">PlayButton</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">&gt;&lt;/</span>
              <span style="color: #000000; ">myctrl:SilverPlayButton</span>
              <span style="color: #000000; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #000000; ">&lt;/</span>
              <span style="color: #000000; ">Canvas</span>
              <span style="color: #000000; ">&gt;</span>
            </div>
          </pre>
        </div>
        <p>
Unfortunately there is a little problem now, the page.xaml doesn't open in Blend anymore
because it cannot find the button. At this moment I don't know how to fix this yet.
I worked around it by adding the button at the last moment, when I didn't need Blend
anymore. 
</p>
        <p>
  
</p>
        <p>
          <i>Animations and Events</i>
        </p>
        <p>
The timelines that were recorded in Blend (see the XAML file) have to be connected
to the mouse events of the Canvas object. The MouseEnter and MouseLeave events are
left out of the code below because it is pretty much the same.
</p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5d9715d0-b684-42a8-bfe8-aab5d4cc67ff" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #0000FF; ">public</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">class</span>
              <span style="color: #000000; "> SilverPlayButton
: Control { </span>
              <span style="color: #0000FF; ">private</span>
              <span style="color: #000000; "> FrameworkElement
implementationRoot; </span>
              <span style="color: #0000FF; ">private</span>
              <span style="color: #000000; "> Canvas
_button; </span>
              <span style="color: #0000FF; ">private</span>
              <span style="color: #000000; "> Storyboard
_mouseDown; </span>
              <span style="color: #0000FF; ">public</span>
              <span style="color: #000000; "> SilverPlayButton()
{ System.IO.Stream s </span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">this</span>
              <span style="color: #000000; ">.GetType().Assembly
.GetManifestResourceStream(</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">SilverlightDemoClasslib.SilverPlayButton.xaml</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">);
implementationRoot </span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">this</span>
              <span style="color: #000000; ">.InitializeFromXaml(</span>
              <span style="color: #0000FF; ">new</span>
              <span style="color: #000000; "> System.IO.StreamReader(s).ReadToEnd()); </span>
              <span style="color: #008000; ">//</span>
              <span style="color: #008000; "> Assign
private variables</span>
              <span style="color: #008000; ">
              </span>
              <span style="color: #000000; "> _button </span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; "> implementationRoot.FindName(</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">button</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">) </span>
              <span style="color: #0000FF; ">as</span>
              <span style="color: #000000; "> Canvas;
_mouseDown </span>
              <span style="color: #000000; ">=</span>
              <span style="color: #000000; "> implementationRoot.FindName(</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">mouseDown</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">) </span>
              <span style="color: #0000FF; ">as</span>
              <span style="color: #000000; "> Storyboard; </span>
              <span style="color: #008000; ">//</span>
              <span style="color: #008000; "> Add
eventhandlers</span>
              <span style="color: #008000; ">
              </span>
              <span style="color: #000000; "> _button.MouseLeftButtonDown </span>
              <span style="color: #000000; ">+=</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">new</span>
              <span style="color: #000000; "> System.Windows.Input
.MouseEventHandler(_arcButton_MouseLeftButtonDown); } </span>
              <span style="color: #0000FF; ">void</span>
              <span style="color: #000000; "> _arcButton_MouseLeftButtonDown(</span>
              <span style="color: #0000FF; ">object</span>
              <span style="color: #000000; "> sender,
System.Windows.Input.MouseEventArgs e) { </span>
              <span style="color: #008000; ">//</span>
              <span style="color: #008000; "> Start
animation</span>
              <span style="color: #008000; ">
              </span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">this</span>
              <span style="color: #000000; ">._mouseDown.Begin();
} }</span>
            </div>
          </pre>
        </div>
        <p>
The last thing to do is to add an eventhandler for the button click in the
page.xaml to start the animation of the picture.
</p>
        <p>
        </p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d6d7f67c-3e38-4939-bbae-25adf4327d46" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #0000FF; ">public</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">partial</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">class</span>
              <span style="color: #000000; "> Page
: Canvas { </span>
              <span style="color: #0000FF; ">public</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">void</span>
              <span style="color: #000000; "> Page_Loaded(</span>
              <span style="color: #0000FF; ">object</span>
              <span style="color: #000000; "> o,
EventArgs e) { InitializeComponent(); PlayButton.MouseLeftButtonDown </span>
              <span style="color: #000000; ">+=</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">new</span>
              <span style="color: #000000; "> MouseEventHandler(PlayButton_MouseLeftButtonDown);
} </span>
              <span style="color: #0000FF; ">void</span>
              <span style="color: #000000; "> PlayButton_MouseLeftButtonDown(</span>
              <span style="color: #0000FF; ">object</span>
              <span style="color: #000000; "> sender,
MouseEventArgs e) { popupImageAnimation.Begin(); } }</span>
            </div>
          </pre>
        </div>
        <p>
          <i>Running Silverlight in dasBlog</i>
        </p>
        <p>
That is not a real problem because, from a server point of view, Silverlight is just
a bunch of javascript code. To get it running you copy the ClientBin folder (including
the dll's), page.xaml file and the javascript files (Silverlight.js and TestPage.html.js)
to the root of your web folder.  However, because I didn't want the root
of my web server to be filled with these kind of files I created a separate ClientScripts
folder for the xaml and js files. When you do so you have to make a change in
the TestPage.html.js, which has a reference to the page.xaml: 
</p>
        <p>
        </p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:78d53863-0172-461a-9d3e-d2a11bb6f1e2" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #000000; ">function
createSilverlight() { Sys.Silverlight.createObjectEx({ source: </span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">ClientScripts/Page.xaml</span>
              <span style="color: #000000; ">"</span>
              <span style="color: #000000; ">,
... } </span>
            </div>
          </pre>
        </div>
        <p>
Now you can add a div to your blog post that acts as the host of the Silverlight
app (note that you add the path to the js files): 
</p>
        <p>
  
</p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3e63479b-3feb-403e-9335-942cb04a4289" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #0000FF; ">&lt;</span>
              <span style="color: #800000; ">script </span>
              <span style="color: #FF0000; ">src</span>
              <span style="color: #0000FF; ">="ClientScripts/Silverlight.js"</span>
              <span style="color: #FF0000; "> type</span>
              <span style="color: #0000FF; ">="text/javascript"</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="background-color: #F5F5F5; color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;/</span>
              <span style="color: #800000; ">script</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;</span>
              <span style="color: #800000; ">script </span>
              <span style="color: #FF0000; ">src</span>
              <span style="color: #0000FF; ">="ClientScripts/TestPage.html.js"</span>
              <span style="color: #FF0000; "> type</span>
              <span style="color: #0000FF; ">="text/javascript"</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="background-color: #F5F5F5; color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;/</span>
              <span style="color: #800000; ">script</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;</span>
              <span style="color: #800000; ">div </span>
              <span style="color: #FF0000; ">id</span>
              <span style="color: #0000FF; ">="SilverlightControlHost"</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;</span>
              <span style="color: #800000; ">script </span>
              <span style="color: #FF0000; ">type</span>
              <span style="color: #0000FF; ">="text/javascript"</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="background-color: #F5F5F5; color: #000000; ">createSilverlight();</span>
              <span style="color: #0000FF; ">&lt;/</span>
              <span style="color: #800000; ">script</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">&lt;/</span>
              <span style="color: #800000; ">div</span>
              <span style="color: #0000FF; ">&gt;</span>
              <span style="color: #000000; ">
              </span>
            </div>
          </pre>
        </div>
        <p>
And it should work...
</p>
        <p>
          <strong>Update:</strong> Removed the demo from this post because it doesn't work anymore
with the new SL versions.
</p>
        <img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=6187afea-da04-4b89-bce2-997bc906c990" />
      </body>
      <title>Silverlight demonstration</title>
      <guid isPermaLink="false">http://www.michelvandervlugt.net/PermaLink,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx</guid>
      <link>http://www.michelvandervlugt.net/PermaLink,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx</link>
      <pubDate>Tue, 26 Jun 2007 20:48:37 GMT</pubDate>
      <description> 
			
&lt;p align="left"&gt;
This blog post is about how to develop a small &lt;a href="http://silverlight.net/" target="_blank"&gt;Silverlight&lt;/a&gt; (the
new MS plug-in for Rich Interactive Applications&amp;nbsp;(RIAs)&amp;nbsp;on the web) application
and get it&amp;nbsp; running inside this post. The demo app is quite simple, it has a
button that pop ups the&amp;nbsp;Silverlight logo when it is pushed.
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;Install development environment&lt;/i&gt; 
&lt;p&gt;
For development of Silverlight apps the Orcas edition of VS is required plus some
additional Silverlight packages, which can be downloaded from the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight
web site&lt;/a&gt;: the runtime 1.1 alpha, development tools for VS Orcas and the SDK for
the necessary documentation and samples. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Using one of the Expression designer tools is optional but if you want to some fancy
design stuff a designer is really a must. For this project I used Expression Blend
2 May Preview as the older version doesn't support Silverlight. 
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;Design with Expression Blend&lt;/i&gt; 
&lt;p&gt;
To get to know a bit about Silverlight and the graphical design possibilities using
Expression Blend I used&amp;nbsp;the great tutorials of &lt;a href="http://www.nibblestutorials.net/" target="_blank"&gt;nibbles
tutorials&lt;/a&gt;. Playing with these tutorials gives you a great insight in using Blend
to create graphical assets and use them in you app. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
For this applications I've created the round button as a user control in a separate
assembly. By adding some animations the button changes color when the mouse enters,
and&amp;nbsp;transforms a little smaller when you click it to create&amp;nbsp;a button down
effect. The rest of the app, including an animation to pop up the picture,&amp;nbsp;is
designed on the page.xaml, which is generated when you create a Silverlight app in
Visual Studio. To use the button (from the separate assembly)&amp;nbsp;on the page you
have to define a namespace&amp;nbsp;in the main canvas of the page.xaml to include the
dll:
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:500c31b3-df4c-40ce-974b-d7cf43a4cc18" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #000000; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;Canvas
xmlns&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;http://schemas.microsoft.com/client/2007&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt; xmlns:x&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt; xmlns:myctrl&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;clr-namespace:SilverlightDemoClasslib;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt; assembly&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;ClientBin&lt;/span&gt;&lt;span style="color: #000000; "&gt;/&lt;/span&gt;&lt;span style="color: #000000; "&gt;SilverlightDemoClasslib.dll&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot; &lt;/span&gt;&lt;span style="color: #000000; "&gt; ... &lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Now you can add the button by including the namespace prefix:
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b4df3105-a1a7-4ee6-acf8-626c15d9a1bc" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #000000; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;Canvas
x:Name&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;buttonCanvas&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt; Canvas.Left&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;15&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt; Canvas.Top&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;55&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;myctrl:SilverPlayButton
x:Name&lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;PlayButton&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000; "&gt;myctrl:SilverPlayButton&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #000000; "&gt;Canvas&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Unfortunately there is a little problem now, the page.xaml doesn't open in Blend anymore
because it cannot find the button. At this moment I don't know how to fix this yet.
I worked around it by adding the button at the last moment, when I didn't need Blend
anymore. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;i&gt;Animations and Events&lt;/i&gt; 
&lt;p&gt;
The timelines that were recorded in Blend (see the XAML file) have to be connected
to the mouse events of the Canvas object. The MouseEnter and MouseLeave events are
left out of the code below because it is pretty much the same.
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5d9715d0-b684-42a8-bfe8-aab5d4cc67ff" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;class&lt;/span&gt;&lt;span style="color: #000000; "&gt; SilverPlayButton
: Control { &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; FrameworkElement
implementationRoot; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; Canvas
_button; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; Storyboard
_mouseDown; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; SilverPlayButton()
{ System.IO.Stream s &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;this&lt;/span&gt;&lt;span style="color: #000000; "&gt;.GetType().Assembly
.GetManifestResourceStream(&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;SilverlightDemoClasslib.SilverPlayButton.xaml&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
implementationRoot &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;this&lt;/span&gt;&lt;span style="color: #000000; "&gt;.InitializeFromXaml(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.IO.StreamReader(s).ReadToEnd()); &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Assign
private variables&lt;/span&gt;&lt;span style="color: #008000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt; _button &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; implementationRoot.FindName(&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;button&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;) &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;as&lt;/span&gt;&lt;span style="color: #000000; "&gt; Canvas;
_mouseDown &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; implementationRoot.FindName(&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;mouseDown&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;) &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;as&lt;/span&gt;&lt;span style="color: #000000; "&gt; Storyboard; &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Add
eventhandlers&lt;/span&gt;&lt;span style="color: #008000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt; _button.MouseLeftButtonDown &lt;/span&gt;&lt;span style="color: #000000; "&gt;+=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.Windows.Input
.MouseEventHandler(_arcButton_MouseLeftButtonDown); } &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; _arcButton_MouseLeftButtonDown(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;object&lt;/span&gt;&lt;span style="color: #000000; "&gt; sender,
System.Windows.Input.MouseEventArgs e) { &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Start
animation&lt;/span&gt;&lt;span style="color: #008000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;this&lt;/span&gt;&lt;span style="color: #000000; "&gt;._mouseDown.Begin();
} }&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
The last thing to do is to add&amp;nbsp;an eventhandler&amp;nbsp;for the button click in the
page.xaml&amp;nbsp;to start the animation of the picture.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d6d7f67c-3e38-4939-bbae-25adf4327d46" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;partial&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;class&lt;/span&gt;&lt;span style="color: #000000; "&gt; Page
: Canvas { &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; Page_Loaded(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;object&lt;/span&gt;&lt;span style="color: #000000; "&gt; o,
EventArgs e) { InitializeComponent(); PlayButton.MouseLeftButtonDown &lt;/span&gt;&lt;span style="color: #000000; "&gt;+=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; MouseEventHandler(PlayButton_MouseLeftButtonDown);
} &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; PlayButton_MouseLeftButtonDown(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;object&lt;/span&gt;&lt;span style="color: #000000; "&gt; sender,
MouseEventArgs e) { popupImageAnimation.Begin(); } }&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;i&gt;Running Silverlight in dasBlog&lt;/i&gt; 
&lt;p&gt;
That is not a real problem because, from a server point of view, Silverlight is just
a bunch of javascript code.&amp;nbsp;To get it running you copy the ClientBin folder (including
the dll's), page.xaml file and the javascript files (Silverlight.js and TestPage.html.js)
to the root of your web folder. &amp;nbsp;However, because I didn't want&amp;nbsp;the root
of my web server to be filled with these kind of files I created a separate&amp;nbsp;ClientScripts
folder for the xaml and&amp;nbsp;js files. When you do so you have to make a change in
the TestPage.html.js, which has a reference to the page.xaml:&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:78d53863-0172-461a-9d3e-d2a11bb6f1e2" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #000000; "&gt;function
createSilverlight() { Sys.Silverlight.createObjectEx({ source: &lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;ClientScripts/Page.xaml&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;,
... } &lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Now you can add&amp;nbsp;a&amp;nbsp;div to your blog post that acts as the host of the Silverlight
app (note that you add the path to the js files): 
&lt;p&gt;
&amp;nbsp; 
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3e63479b-3feb-403e-9335-942cb04a4289" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;script &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;src&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;ClientScripts/Silverlight.js&amp;quot;&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; type&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;script&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;script &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;src&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;ClientScripts/TestPage.html.js&amp;quot;&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; type&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;script&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;div &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;id&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;SilverlightControlHost&amp;quot;&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;script &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;type&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="background-color: #F5F5F5; color: #000000; "&gt;createSilverlight();&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;script&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;div&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
And it should work...
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update:&lt;/strong&gt; Removed the demo from this post because it doesn't work anymore
with the new SL versions.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=6187afea-da04-4b89-bce2-997bc906c990" /&gt;</description>
      <comments>http://www.michelvandervlugt.net/CommentView,guid,6187afea-da04-4b89-bce2-997bc906c990.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.michelvandervlugt.net/Trackback.aspx?guid=cc02d07d-d429-4ade-9ee1-2dc3c4d00eea</trackback:ping>
      <pingback:server>http://www.michelvandervlugt.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.michelvandervlugt.net/PermaLink,guid,cc02d07d-d429-4ade-9ee1-2dc3c4d00eea.aspx</pingback:target>
      <dc:creator>Michel van der Vlugt</dc:creator>
      <wfw:comment>http://www.michelvandervlugt.net/CommentView,guid,cc02d07d-d429-4ade-9ee1-2dc3c4d00eea.aspx</wfw:comment>
      <wfw:commentRss>http://www.michelvandervlugt.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cc02d07d-d429-4ade-9ee1-2dc3c4d00eea</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Test Driven Development is a great thing in software development as it makes it possible
to verify your code very easily during development and when you have to make
changes. However, it is not always easy to write solid unit tests when external influences
are involved. 
</p>
        <p>
For example, in case of Web Services you might want to avoid the actual Web Service
calls in your unit tests for reasons like availability, performance, predictability,
... of the Web Service. In my case I had to avoid the Web Services because
I couldn't rely on the information they returned (the content of the underlying ERP database
was out of my control).
</p>
        <p>
To solve this problem for the unit tests and get a predictable response that
can be tested there are basically two solutions:
</p>
        <ul>
          <li>
Create a dummy Web Service that replaces the actual Web Service; 
</li>
          <li>
Replace the proxy of Web Service in the project by a dummy proxy.</li>
        </ul>
        <p>
In my project I choose for the latter on, based on a technique that is described in
a blog post by <a href="http://blogs.msdn.com/davidwaddleton/archive/2006/08/03/687841.aspx" target="_blank">David
Waddleton</a>. The trick that makes this technique possible and fairly easy is that
the generated proxy is a partial class (.NET 2.0). This makes it possible to define
an interface on the generated proxy (without changing it) by writing your own partial
class. The service consumer can now communicate with the Web Service using the interface
instead of directly to the Web Service. At this point you are free to replace the
Web Service implementation for a mock object during the unit tests using some form
of dependency injection.
</p>
        <p>
          <br />
        </p>
        <center>
          <a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WebServiceMockTechnique_EF73/ClassDiagram_2.jpg" atomicselection="true">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="384" alt="ClassDiagram" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WebServiceMockTechnique_EF73/ClassDiagram_thumb_2.jpg" width="619" border="0" />
          </a>
        </center>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
Note: In the picture above the class MyService is displayed as two classes for clarity
of the concept, in reality this is only one class implemented in two cs files.
</p>
        <p>
Creating the interface might seem to be a lot of work, especially for larger
Web Services, but it can easily be generated using the refactor tool [Extract
Interface] on the proxy class defined in Reference.cs. The implementation of the partial
MyService class stays empty, it only defines the interface IMyService (the implementation
of IMyService is in the generated proxy).
</p>
        <p>
For dependency injection I've used a simple factory class that either instantiates
the Web Service or, in case of the unit tests, an instance of a mock object defined
in the web.config.
</p>
        <p>
However, as easy this is in C# 2.0 it cannot be implemented the same way in VB.NET.
The reason is that VB.NET doesn't support implicit interface implementation, you have
to define the interface implementation explicitly using the Implements keyword:
</p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1a82eaec-3b4d-4537-9f58-a28ad927b5f2" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; width: 441px; padding-top: 0px">
          <pre style="background-color:White;">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: #0000FF; ">Public</span>
              <span style="color: #000000; ">
              </span>
              <span style="color: #0000FF; ">Function</span>
              <span style="color: #000000; "> DoSomething() </span>
              <span style="color: #0000FF; ">Implements</span>
              <span style="color: #000000; "> IMyService.DoSomething </span>
              <span style="color: #0000FF; ">End
Function</span>
            </div>
          </pre>
        </div>
        <p>
This is too bad because you either have to alter Reference.cs (which you shouldn't
because when you update the web reference you loose the changes) or implement new
properties/functions in the otherwise empty class MyService and map them to the Web
Service, which is a lot more work. 
</p>
        <br />
        <p>
The source code can be downloaded from here: <a href="http://www.michelvandervlugt.net/content/binary/WebServiceMockTechnique.zip">WebServiceMockTechnique.zip
(62,52 KB)</a></p>
        <img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=cc02d07d-d429-4ade-9ee1-2dc3c4d00eea" />
      </body>
      <title>Web Service Mock Technique</title>
      <guid isPermaLink="false">http://www.michelvandervlugt.net/PermaLink,guid,cc02d07d-d429-4ade-9ee1-2dc3c4d00eea.aspx</guid>
      <link>http://www.michelvandervlugt.net/PermaLink,guid,cc02d07d-d429-4ade-9ee1-2dc3c4d00eea.aspx</link>
      <pubDate>Mon, 18 Jun 2007 18:15:04 GMT</pubDate>
      <description>&lt;p&gt;
Test Driven Development is a great thing in software development as it makes it possible
to verify your code very easily during development and when&amp;nbsp;you have to make
changes. However, it is not always easy to write solid unit tests when external influences
are involved.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
For example, in case of Web Services you might want to avoid the actual Web Service
calls in your unit tests for reasons like availability, performance, predictability,
...&amp;nbsp;of the Web Service.&amp;nbsp;In my case I had to avoid the Web Services because
I couldn't rely on the information they returned (the content of the underlying ERP&amp;nbsp;database
was out of my control).
&lt;/p&gt;
&lt;p&gt;
To solve this problem for the unit tests and get&amp;nbsp;a predictable response&amp;nbsp;that
can be tested there are basically two solutions:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Create a dummy Web Service that replaces the actual Web Service; 
&lt;li&gt;
Replace the proxy of Web Service&amp;nbsp;in the project by a dummy proxy.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In my project I choose for the latter on, based on a technique that is described in
a blog post&amp;nbsp;by&amp;nbsp;&lt;a href="http://blogs.msdn.com/davidwaddleton/archive/2006/08/03/687841.aspx" target="_blank"&gt;David
Waddleton&lt;/a&gt;. The trick that makes this technique possible and fairly easy is that
the generated proxy is a partial class (.NET 2.0). This makes it possible to define
an interface on the generated proxy (without changing it) by writing your own partial
class. The service consumer can now communicate with the Web Service using the interface
instead of directly to the Web Service. At this point you are free to replace the
Web Service implementation for a mock object during the unit tests using some&amp;nbsp;form
of dependency injection.
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;center&gt;&lt;a href="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WebServiceMockTechnique_EF73/ClassDiagram_2.jpg" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="384" alt="ClassDiagram" src="http://www.michelvandervlugt.net/content/binary/WindowsLiveWriter/WebServiceMockTechnique_EF73/ClassDiagram_thumb_2.jpg" width="619" border="0"&gt;&lt;/a&gt;
&lt;/center&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Note: In the picture above the class MyService is displayed as two classes for clarity
of the concept, in reality this is only one class implemented in two cs files.
&lt;/p&gt;
&lt;p&gt;
Creating the&amp;nbsp;interface might seem to be a lot of work, especially&amp;nbsp;for larger
Web Services, but&amp;nbsp;it can easily be generated using the refactor tool [Extract
Interface] on the proxy class defined in Reference.cs. The implementation of the partial
MyService class stays empty, it only&amp;nbsp;defines the interface IMyService (the implementation
of IMyService is&amp;nbsp;in the generated proxy).
&lt;/p&gt;
&lt;p&gt;
For dependency injection I've used a simple factory class that either instantiates
the Web Service or, in case of the unit tests,&amp;nbsp;an instance of a mock object defined
in the web.config.
&lt;/p&gt;
&lt;p&gt;
However, as easy this is in C# 2.0&amp;nbsp;it cannot be implemented the same way in&amp;nbsp;VB.NET.
The reason is that VB.NET doesn't support implicit interface implementation, you have
to define the interface implementation explicitly using the Implements keyword:
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1a82eaec-3b4d-4537-9f58-a28ad927b5f2" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; width: 441px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;Public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;Function&lt;/span&gt;&lt;span style="color: #000000; "&gt; DoSomething() &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;Implements&lt;/span&gt;&lt;span style="color: #000000; "&gt; IMyService.DoSomething &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;End
Function&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
This is too bad because you either have to alter Reference.cs (which you shouldn't
because when you update the web reference you loose the changes) or implement new
properties/functions in the otherwise empty class MyService and map them to the Web
Service, which is a lot more work.&amp;nbsp;
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
The source code can be downloaded from here: &lt;a href="http://www.michelvandervlugt.net/content/binary/WebServiceMockTechnique.zip"&gt;WebServiceMockTechnique.zip
(62,52 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.michelvandervlugt.net/aggbug.ashx?id=cc02d07d-d429-4ade-9ee1-2dc3c4d00eea" /&gt;</description>
      <comments>http://www.michelvandervlugt.net/CommentView,guid,cc02d07d-d429-4ade-9ee1-2dc3c4d00eea.aspx</comments>
      <category>.NET;C#;VB.NET</category>
    </item>
  </channel>
</rss>