<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Silverlight</title>
        <link>http://geekswithblogs.net/HouseOfBilz/category/9622.aspx</link>
        <description>Silverlight</description>
        <language>en-US</language>
        <copyright>Brian Genisio's House Of Bilz</copyright>
        <managingEditor>BrianGenisio@Gmail.Com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Adventures in MVVM &amp;ndash; Model-View-ViewModel</title>
            <link>http://geekswithblogs.net/HouseOfBilz/archive/2009/05/22/adventures-in-mvvm-ndash-model-view-viewmodel.aspx</link>
            <description>&lt;p&gt;This post is intended to be a high-level post intended to index all of my “Adventures in MVVM” posts.  I will be traveling the region this summer giving talks on the MVVM pattern and these posts are part of me working through the details of the MVVM pattern.  These posts will not include the “What”.  There are &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx"&gt;several&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;good&lt;/a&gt; &lt;a href="http://channel9.msdn.com/shows/Continuum/MVVM/"&gt;articles&lt;/a&gt; on the &lt;a href="http://karlshifflett.wordpress.com/2008/11/08/learning-wpf-m-v-vm/"&gt;web&lt;/a&gt; that do that already.  Instead, I will be taking a deeper dive into MVVM and writing on the “How” and “Why” of the MVVM pattern.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://houseofbilz.com/archive/2009/05/22/adventures-in-mvvm-ndash-commands-in-silverlight.aspx"&gt;Commands in Silverlight&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://houseofbilz.com/archive/2009/05/27/adventures-in-mvvm-ndash-a-testing-story.aspx"&gt;A Testing Story&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/05/29/adventures-in-mvvm-ndash-commanding-with-list-boxes.aspx"&gt;Commanding with List Boxes&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/06/12/adventures-in-mvvm-ndash-slides-and-demo-app.aspx"&gt;Demo Application and Slides&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://houseofbilz.com/HouseOfBilz/archive/2009/06/19/adventures-in-mvvm----ball-of-mud-vs-mvvm.aspx"&gt;“Ball of Mud” vs MVVM&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/08/07/adventures-in-mvvm-ndash-mvvm-interview.aspx"&gt;My MVVM Interview with David Giard&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/08/21/adventures-in-mvvm-ndash-generalized-command-behavior-attachments.aspx"&gt;Generalized Command Behavior Attachments&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/08/27/adventures-in-mvvm-ndash-binding-commands-to-any-event.aspx"&gt;Binding Commands to ANY Event&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://geekswithblogs.net/HouseOfBilz/archive/2009/10/20/adventures-in-mvvm-ndash-a-rails-inspired-viewmodel.aspx"&gt;A Rails-Inspired ViewModel&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://houseofbilz.com/archive/2009/11/14/adventures-in-mvvm----dependant-properties-with-inotifypropertychanged.aspx"&gt;Dependant Properties with INotifyPropertyChanged&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132377"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132377" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/HouseOfBilz/aggbug/132377.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Genisio's House Of Bilz</dc:creator>
            <guid>http://geekswithblogs.net/HouseOfBilz/archive/2009/05/22/adventures-in-mvvm-ndash-model-view-viewmodel.aspx</guid>
            <pubDate>Sat, 23 May 2009 08:52:45 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/HouseOfBilz/comments/132377.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/HouseOfBilz/archive/2009/05/22/adventures-in-mvvm-ndash-model-view-viewmodel.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/HouseOfBilz/comments/commentRss/132377.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/HouseOfBilz/services/trackbacks/132377.aspx</trackback:ping>
        </item>
        <item>
            <title>Binding to Resources in Silverlight/WPF</title>
            <link>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/15/binding-to-resources-in-silverlightwpf.aspx</link>
            <description>&lt;a rev="vote-for" href="http://dotnetshoutout.com/Binding-to-Resources-in-SilverlightWPF"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fwww.houseofbilz.com%2Farchive%2F2009%2F03%2F15%2Fbinding-to-resources-in-silverlightwpf.aspx" /&gt;&lt;/a&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.houseofbilz.com%2farchive%2f2009%2f03%2f15%2fbinding-to-resources-in-silverlightwpf.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.houseofbilz.com%2farchive%2f2009%2f03%2f15%2fbinding-to-resources-in-silverlightwpf.aspx" /&gt;&lt;/a&gt;   &lt;p&gt;This article is describing how to solve the problem in SIlverlight, but the problem can be solved in WPF using the exact same technique.&lt;/p&gt;  &lt;p&gt;So, now it is time to internationalize our application.  I want to use the &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163609.aspx"&gt;built-in "resx" mechanism&lt;/a&gt; for i18n in .net, so I create myself a resource file and start adding strings to the table:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/HouseOfBilz/WindowsLiveWriter/BindingtoResourcesinSilverlightWPF_C384/image_4.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://geekswithblogs.net/images/geekswithblogs_net/HouseOfBilz/WindowsLiveWriter/BindingtoResourcesinSilverlightWPF_C384/image_thumb_1.png" width="600" height="223" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Visual Studio automatically generates the resource class for me, and I am ready to bind to the data in my XAML:&lt;/p&gt;  &lt;pre class="xml" name="code"&gt;&amp;lt;UserControl.Resources&amp;gt;
    &amp;lt;l:i18n x:Key="i18n" /&amp;gt;
&amp;lt;/UserControl.Resources&amp;gt;

&amp;lt;StackPanel x:Name="LayoutRoot" Orientation="Horizontal"&amp;gt;
    &amp;lt;TextBox /&amp;gt;
    &amp;lt;Button Content="{Binding Path=SearchButton, Source={StaticResource i18n}}" /&amp;gt;
&amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;

&lt;p&gt;But I run my application and I get this exception: &lt;strong&gt;Unhandled Error in Silverlight 2 Application AG_E_PARSER_BAD_TYPE&lt;/strong&gt;.  I get this error message because the resx file is set to create my resource class as an "internal" class.  Essentially, the SIlverlight engine doesn't have permission to instantiate a new i18n object, and it dies.&lt;/p&gt;

&lt;p&gt;Fortunately, in Visual Studio 2008, they have given us a way to solve this problem.  In the Resx editor, you can change the protection of the class it generates from internal to public.  So, I do exactly that:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/HouseOfBilz/WindowsLiveWriter/BindingtoResourcesinSilverlightWPF_C384/image_6.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://geekswithblogs.net/images/geekswithblogs_net/HouseOfBilz/WindowsLiveWriter/BindingtoResourcesinSilverlightWPF_C384/image_thumb_2.png" width="595" height="223" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now my XAML should be able to bind to the resource, right?  Wrong: &lt;strong&gt;Unhandled Error in Silverlight 2 Application AG_E_PARSER_UNKNOWN_TYPE&lt;/strong&gt;.  This time, it is complaining because the constructor to this public class that Visual Studio generated is internal!  The class is public, but the constructor is internal, so the Silverlight/WPF engine still can't instantiate the object.&lt;/p&gt;

&lt;p&gt;I searched the interwebs, and I'm not alone with this problem.  Most people solve the problem by adding a custom build step that modifies the code.  Some even suggest changing the constructor to public by hand every time you update the resource table.  I am here to say: THERE IS A BETTER WAY!  I just created a public class with a single property that exposes the class:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;public class i18nPublic
{
    private readonly static i18n resources = new i18n();
    public i18n Strings { get { return resources; } }
}&lt;/pre&gt;

&lt;p&gt;By adding this class, I can make a slight modification to the resource type and the binding path and I am now binding directly to the resources.&lt;/p&gt;

&lt;pre class="xml" name="code"&gt;&amp;lt;UserControl.Resources&amp;gt;
  &amp;lt;l:i18nPublic x:Key="i18n" /&amp;gt;
&amp;lt;/UserControl.Resources&amp;gt;

&amp;lt;StackPanel x:Name="LayoutRoot" Orientation="Horizontal"&amp;gt;
    &amp;lt;TextBox /&amp;gt;
    &amp;lt;Button Content="{Binding Path=Strings.SearchButton, Source={StaticResource i18n}}" /&amp;gt;
&amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130092"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130092" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/HouseOfBilz/aggbug/130092.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Genisio's House Of Bilz</dc:creator>
            <guid>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/15/binding-to-resources-in-silverlightwpf.aspx</guid>
            <pubDate>Sun, 15 Mar 2009 14:15:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/HouseOfBilz/comments/130092.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/15/binding-to-resources-in-silverlightwpf.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/HouseOfBilz/comments/commentRss/130092.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/HouseOfBilz/services/trackbacks/130092.aspx</trackback:ping>
        </item>
        <item>
            <title>My Silverlight 3 Wish List</title>
            <link>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/06/my-silverlight-3-wish-list.aspx</link>
            <description>&lt;a rev="vote-for" href="http://dotnetshoutout.com/My-Silverlight-3-Wish-List"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fwww.houseofbilz.com%2Farchive%2F2009%2F03%2F06%2Fmy-silverlight-3-wish-list.aspx" /&gt;&lt;/a&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.houseofbilz.com%2farchive%2f2009%2f03%2f06%2fmy-silverlight-3-wish-list.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.houseofbilz.com%2farchive%2f2009%2f03%2f06%2fmy-silverlight-3-wish-list.aspx" /&gt;&lt;/a&gt;   &lt;p&gt;I have been developing full time in Silverlight 2 for a few months now.  I must say, it is the most fun environment I have ever programmed in.  It has been an enabling technology in our product, and I am rather excited to see what comes next.  If the pattern continues as I expect it probably will, we will hear all about the features of Silverlight 3 in a few weeks at &lt;a href="http://visitmix.com/"&gt;Mix 09&lt;/a&gt;.  I will not be attending this conference, but I fully expect to be watching the important sessions virtually.  I am hoping for a lot.  You see, as much as I like the SIlverlight framework, it is missing some significant features that I can really use.&lt;/p&gt;  &lt;p&gt;So, I figured I would publish my Silverlight 3 wish list.  Some of these things are more important than others, but all of them are things that would make my "Rich Internet Application" more rich. &lt;strong&gt;I don't want this list to sound like I am just a big complainer.  &lt;/strong&gt;I think I am exercising the framework pretty hard, and Microsoft can only make the framework better with this list.  &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;MediaElement frame rate control: &lt;/strong&gt;The Silverlight media element is missing the ability to control the frame rate.  This keeps us from controlling the playback for slow-motion or fast-forward.  I have to imagine that the sports domain wants this as well.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;MediaElement loop control: &lt;/strong&gt;The current media element does not support looping of video content.  It can be programmed by hooking the "MediaEnded" event, putting the position at zero, and playing again, but this causes a noticeable pause.  This pause keeps looping play from being fluid.  It would be nice if the media element supported it directly.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Native video rendering: &lt;/strong&gt;Silverlight 2 does not use any hardware capabilities for video playback -- it is all done in software.  Therefore, the playback takes a lot of processor power.  This is really noticeable when four videos are playing simultaneously.  Any more on modern hardware is often choppy.  I would like to be able to play as many as nine videos at once.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3D support: &lt;/strong&gt;Similar to the previous wish, Silverlight 2 does not use the video hardware directly.  This means that there is no 3D support.  It would be nice to see some 3D capabilities in Silverlight 3 -- preferably handled by hardware.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Direct bitmap manipulation: &lt;/strong&gt;Silverlight 2 does not support this, and there are certain types of effects and manipulations that are not possible in Silverlight.  I would love to see some bitmap manipulation capabilities&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Support for other data transports: &lt;/strong&gt;Currently, only HTTP requests are made available through the SIlverlight plug-in.  This limits the use of more sophisticated WCF bindings.  At a very minimum, it would be nice to be able to use TCP bindings via WCF.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Better mouse support: &lt;/strong&gt;Currently, we need to &lt;a href="http://www.houseofbilz.com/archive/2009/03/01/right-clicking-in-silverlight-2----a-refinement.aspx"&gt;hack in right-click&lt;/a&gt;, double-click and scroll-wheel capabilities.  It would be nice to have native support.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Support for drag-and-drop: &lt;/strong&gt;This is another case where I have &lt;a href="http://www.houseofbilz.com/archive/2009/02/10/drag-and-drop-with-silverlight.aspx"&gt;hacked something together&lt;/a&gt;, but it would be great if I were able to rely on the framework.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Native support for the MVVM pattern: &lt;/strong&gt;As far as I have figured, the MVVM pattern is the most suitable pattern for most large-scale Silverlight development.  It allows us to test the majority of our code and keep it out of the view.  Unfortunately, I haven't found MVVM to be well supported in the framework.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Commands -- They gave us ICommand, but nothing else.  I have hacked something in, but native support would be nice. &lt;/li&gt;    &lt;li&gt;See what &lt;a href="http://projects.nikhilk.net/SilverlightFX/"&gt;Silverlight.FX&lt;/a&gt; and &lt;a href="http://www.codeplex.com/caliburn"&gt;Cliburn&lt;/a&gt; have done.  Can we get something like this in the framework? &lt;/li&gt;    &lt;li&gt;Some sort of "Inversion of Control" or similar decoupling support?  Might MEF or Prism show up in SIlverlight 3? &lt;/li&gt;    &lt;li&gt;Stand-alone binding -- As far as I can tell, binding is only available in controls.  I can't write tests against controls.  I often want to bind data in my model to my view model.  I have written my own binder for this, but it would be nice to have some built-in support &lt;/li&gt;    &lt;li&gt;Better property notification.  INotifyPropertyChanged creates a lot of boiler-plate code in the view model.  I have minimized this by using a "property bag", but some utilities that make view models easier to write would be nice. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Interprocess communication: &lt;/strong&gt;I would like the ability to talk to other non-silverlight processes.  This seems like a tall order, but I have some business cases for this.&lt;/p&gt;  &lt;p&gt;That is all I have for now.  I am sure there is more that I am not thinking of.  I come across different needs every day.  For most cases, I have been able to hack some sort of support in when I need it.  In some cases, like the video playback support, I can't hack my wan out of the limitations.  &lt;/p&gt;  &lt;p&gt;This list looks like a lot now that I have written it down.  I am very curious to know if I will be getting any of these features.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129897"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129897" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/HouseOfBilz/aggbug/129897.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Genisio's House Of Bilz</dc:creator>
            <guid>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/06/my-silverlight-3-wish-list.aspx</guid>
            <pubDate>Sat, 07 Mar 2009 09:31:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/HouseOfBilz/comments/129897.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/HouseOfBilz/archive/2009/03/06/my-silverlight-3-wish-list.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/HouseOfBilz/comments/commentRss/129897.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/HouseOfBilz/services/trackbacks/129897.aspx</trackback:ping>
        </item>
        <item>
            <title>Drag and Drop with Silverlight</title>
            <link>http://geekswithblogs.net/HouseOfBilz/archive/2009/02/10/drag-and-drop-with-silverlight.aspx</link>
            <description>&lt;a href="http://dotnetshoutout.com/Drag-and-Drop-with-Silverlight" rev="vote-for"&gt;&lt;img style="border: 0px none ;" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fhouseofbilz.com%2Farchive%2F2009%2F02%2F10%2Fdrag-and-drop-with-silverlight.aspx" alt="Shout it" /&gt;&lt;/a&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fhouseofbilz.com%2farchive%2f2009%2f02%2f10%2fdrag-and-drop-with-silverlight.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fhouseofbilz.com%2farchive%2f2009%2f02%2f10%2fdrag-and-drop-with-silverlight.aspx" /&gt;&lt;/a&gt;
&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;I have been developing with Silverlight for a few months now, and I have really been enjoying myself.  It has been the enabling technology my project and we have been extremely productive in the environment.  Unfortunately, Silverlight is still in version 2.0 and there are some missing capabilities.&lt;/p&gt;
&lt;p&gt;One such hole in the framework is "Drag and Drop".  There is no support for it directly.  There are several blog examples on the web, but I have yet to find a fully encapsulated, generic solution to the "Drag and Drop" problem.  For instance, how soon after dragging do you really want to be dragging?  You don't want to drag immediately, as that will affect normal clicking on an element.  How do you handle drags from one distinct control to another that are not aware of each other?  How do you clue the user in that a given control is droppable?  How do you add animation to cue the user that the item is being dropped?&lt;/p&gt;
&lt;h3&gt;Introducing DragNDrop&lt;/h3&gt;
&lt;p&gt;To answer these questions, I created the &lt;strong&gt;DragNDrop&lt;/strong&gt; class.  It is a manager of sorts, and watches a "Drag Source" for the mouse down events.  The "Drag Source" implements an interface and the "Drop Spot" implements a complimentary interface.  This allows for the "Drag Source" and "Drop Spot" to be blissfully unaware of each other.&lt;/p&gt;
&lt;h3&gt;Usage&lt;/h3&gt;
&lt;p&gt;The assumption made with this class is that there is some sort of a payload.  This payload is picked up from the "Drag Source" and dropped into the "Drop Spot".  The "Drop Spot" can accept a payload of any types that it implements from any "Drag Source" that implements the complementary interface.  Lets take a look at the interfaces:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public class DragNDrop&amp;lt;PayloadType&amp;gt;
{
    public interface IThumbnailDragSource
    {
        FrameworkElement DragCursor { get; }
        PayloadType Payload { get; }
    }
    
    public interface IThumbnailDropSpot
    {
        void DragDropEnter();
        void DragDropExit();  
        void ThumbnailDroping(PayloadType dataContext, FrameworkElement cursor, Point cursorPosition);
    }
}&lt;/pre&gt;
&lt;p&gt;For instance, if a "Drag Source" wanted to allow dragging with a string payload, it would implement &lt;strong&gt;DragNDrop&amp;lt;string&amp;gt;.IThumbnailDragSource&lt;/strong&gt;.  Any "Drop Spot" that wants to accept a string payload would implement &lt;strong&gt;DragNDrop&amp;lt;string&amp;gt;.IThumbnailDropSpot&lt;/strong&gt;.  The &lt;strong&gt;DragNDrop&lt;/strong&gt; class is then constructed with an instance of the "Drag Source" and the &lt;strong&gt;DragNDrop&lt;/strong&gt; class handles everything else.&lt;/p&gt;
&lt;p&gt;In addition to the payload, the "Drag Source" needs to provide the &lt;strong&gt;DragNDrop&lt;/strong&gt; class with the cursor that will be displayed and dragged across the screen.  This can be anything; an image, a user control, a rectangle, etc.&lt;/p&gt;
&lt;p&gt;The "Drop Spot" will be notified when the cursor is entering and exiting its space, so it can react appropriately.  It will also be notified when the payload is dropped with the instance of the cursor and the absolute position.  This is necessary in case the "Drop Spot" wants to animate the drop in any way.&lt;/p&gt;
&lt;h3&gt;The Demo&lt;/h3&gt;
&lt;p&gt;I created the &lt;a href="http://brianstestsite.googlepages.com/DragAndDrop.html"&gt;Twitter Search Tool&lt;/a&gt; to prove out this concept.  The idea is that search for a term and it returns a list of tweets. When you find a tweet that you like, you can drop it on to the second list to keep track of it.  It is not the most functional app in the world, but it illustrates the usage of the &lt;strong&gt;DragNDrop&lt;/strong&gt; class nicely.  Take a moment to try it out.&lt;/p&gt;
&lt;p&gt;Now that you have seen it in action, lets take a look at how I use the &lt;strong&gt;DragNDrop&lt;/strong&gt; class.  This application uses a small data structure called &lt;strong&gt;Tweet&lt;/strong&gt;.  It contains all of the information about a given tweet (user name, user image, text, etc).  The &lt;strong&gt;Tweet&lt;/strong&gt; is the payload.&lt;/p&gt;
&lt;p&gt;In the Silverlight UI, I created a user control to represent each item in the list called &lt;strong&gt;ListItem&lt;/strong&gt;.  The XAML is available in the full source if you are curious.&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public partial class ListItem : UserControl, DragNDrop&amp;lt;Tweet&amp;gt;.IThumbnailDragSource
{
    private readonly DragNDrop&amp;lt;Tweet&amp;gt; _dragNDrop;

    public ListItem()
    {
        InitializeComponent();

        _dragNDrop = new DragNDrop&amp;lt;Tweet&amp;gt;(this);
        _dragNDrop.DraggingEnabledDistance = 5.0;
    }

    public FrameworkElement DragCursor
    {
        get
        {
            return new Image
            {
                Width = TweetImage.ActualWidth,
                Height = TweetImage.ActualHeight,
                Source = TweetImage.Source,
                Opacity = 0.5
            };
        }
    }

    public Tweet Payload
    {
        get { return DataContext as Tweet; }
    }
}&lt;/pre&gt;
&lt;p&gt;This code is pretty straight-forward.  The DragCursor returns a new image with the picture of the user.  The payload is the actual Tweet.  The constructor creates an instance of &lt;strong&gt;DragNDrop&lt;/strong&gt; and passes itself in as the source.  It also sets the &lt;strong&gt;DraggingEnabledDistance&lt;/strong&gt;.  This is the distance (in pixels) that the user must drag before the dragging really begins.  The default is 10 pixels.&lt;/p&gt;
&lt;p&gt;Next, lets take a look at the "Drop Spot" code.  It is also a user control, &lt;strong&gt;TweetDropList,&lt;/strong&gt; which includes a ListBox control.  It also includes an opaque canvas that gives the effect of highlighting when it is made visible.&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public partial class TweetDropList : DragNDrop&amp;lt;Tweet&amp;gt;.IThumbnailDropSpot
{
    private readonly ObservableCollection&amp;lt;Tweet&amp;gt; _savedTweets = new ObservableCollection&amp;lt;Tweet&amp;gt;();

    public TweetDropList()
    {
        InitializeComponent();
        DropList.ItemsSource = _savedTweets;
    }

    public void DragDropEnter()
    {
        Highlight.Visibility = Visibility.Visible;
    }

    public void DragDropExit()
    {
        Highlight.Visibility = Visibility.Collapsed;
    }

    public void ThumbnailDroping(Tweet dataContext, FrameworkElement cursor, Point cursorPosition)
    {
        DragDropExit();
        AnimateCursor(cursor, cursorPosition, () =&amp;gt; _savedTweets.Add(dataContext));
    }
}&lt;/pre&gt;
&lt;p&gt;I have left out the &lt;strong&gt;AnimateCursor&lt;/strong&gt; code, but it simply generates a storyboard on the cursor and quickly morphs it down to a size of zero.  That code can be found in the source bundle.  The rest of this implementation is extremely simple.  &lt;strong&gt;DragDropEnter&lt;/strong&gt; and &lt;strong&gt;DragDropExit&lt;/strong&gt; simply hides and shows the highlight layer.  &lt;strong&gt;ThumbnailDropping&lt;/strong&gt; will remove the highlighting layer and animate the cursor to give the effect of the item being dropped.  When the animation completes, the new tweet is added to the &lt;strong&gt;_savedTweets&lt;/strong&gt; collection, which will cause the&lt;strong&gt; &lt;/strong&gt;user control to display the new tweet.&lt;/p&gt;
&lt;h3&gt;Thats It!&lt;/h3&gt;
&lt;p&gt;I designed the &lt;strong&gt;DragNDrop&lt;/strong&gt; class to be as simple to use as possible.  I have been using a version of this class in my product and I have had great results.  The "Drop Spots" can implement as many versions of &lt;strong&gt;IThumbnailDropSpot&lt;/strong&gt; as it needs to allow different types of items to be dragged.  The &lt;strong&gt;DragNDrop&lt;/strong&gt; class can be instantiated as many times as necessary, for every "Drag Source".  &lt;/p&gt;
&lt;p&gt;Please play with this class and give me feedback.  I'd love to hear how it is being used.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://brianstestsite.googlepages.com/DragAndDrop.html"&gt;DragNDrop Twitter Demo&lt;/a&gt;     &lt;br /&gt;
&lt;a href="http://brianstestsite.googlepages.com/DragNDrop_Source.zip"&gt;DragNDrop Twitter Demo Source&lt;/a&gt;     &lt;br /&gt;
&lt;a href="http://brianstestsite.googlepages.com/DragNDrop.cs"&gt;DragNDrop.cs&lt;/a&gt;     &lt;br /&gt;
&lt;a href="http://brianstestsite.googlepages.com/Extensisons.cs"&gt;Extensions.cs&lt;/a&gt; (a handful of extension methods that DragNDrop uses)&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129320"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=129320" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/HouseOfBilz/aggbug/129320.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Genisio's House Of Bilz</dc:creator>
            <guid>http://geekswithblogs.net/HouseOfBilz/archive/2009/02/10/drag-and-drop-with-silverlight.aspx</guid>
            <pubDate>Wed, 11 Feb 2009 09:49:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/HouseOfBilz/comments/129320.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/HouseOfBilz/archive/2009/02/10/drag-and-drop-with-silverlight.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/HouseOfBilz/comments/commentRss/129320.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/HouseOfBilz/services/trackbacks/129320.aspx</trackback:ping>
        </item>
    </channel>
</rss>