<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sander van Vliet &#187; .Net</title>
	<atom:link href="http://barad-dur.nl/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://barad-dur.nl</link>
	<description>Land Rovers, .Net en meer!</description>
	<lastBuildDate>Wed, 21 Apr 2010 09:47:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>.Net 4.0 WinForm Data Binding bug</title>
		<link>http://barad-dur.nl/net/net-4-0-winform-data-binding-bug/</link>
		<comments>http://barad-dur.nl/net/net-4-0-winform-data-binding-bug/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 09:37:35 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C# 4.0]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=158</guid>
		<description><![CDATA[Currently I&#8217;m busy with converting a .Net 2.0 WinForms application to .Net 4.0 in VS2010. Seemed to work pretty smooth but when testing one of the more complex windows in the application I hit a snag. Upon opening the window I got a &#8220;TargetException: Object does not match target type.&#8221; thrown in my face. After <a href="http://barad-dur.nl/net/net-4-0-winform-data-binding-bug/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Currently I&#8217;m busy with converting a .Net 2.0 WinForms application to .Net 4.0 in VS2010. Seemed to work pretty smooth but when testing one of the more complex windows in the application I hit a snag. Upon opening the window I got a &#8220;TargetException: Object does not match target type.&#8221; thrown in my face. After a quick tour with the debugger I found the problem: data binding didn&#8217;t work anymore!</p>
<p>To find out what the real problem was I&#8217;ve built a test application that basically does the same thing as the complex window that is giving me such a headache.<span id="more-158"></span> So here goes:</p>
<p>I have a class like this:</p>
<pre>public class Base {
    public string Property1 { get; set; }
    public Sub SubItem { get; set; }

    public Base() {
        Property1 = "Base Property1";
        SubItem = new Sub();
}
public class Sub {
    public string Property1 { get; set; }

    public Sub() {
        Property1 = "Sub Property1";
    }
}
</pre>
<p>Which is bound to a TextBox:</p>
<pre>private void buttonBind_Click(object sender, EventArgs e) {
    Base b = new Base();

    // This works
    textBox1.DataBindings.Add("Text", b.SubItem, "Property1");

    // This doesn't work
    textBox2.DataBindings.Add("Text", b, "SubItem.Property1");
}
</pre>
<p>Now the first binding will work but the second one will throw a TargetException. I have no clue why this happens but the message of the exception and the stack trace give some hints that this is a reflection problem. However the binding specifies to bind a string property to a string property so that shouldn&#8217;t be a problem.</p>
<p>A workaround for this problem is to use a BindingSource:</p>
<pre>private void buttonBind_Click(object sender, EventArgs e) {
    Base b = new Base();
    BindingSource bs = new BindingSource(b, null); // Use a empty datamember

    // Now it will work
    textBox2.DataBindings.Add("Text", bs, "SubItem.Property1");
}</pre>
<p>But it&#8217;s quite a lot of work to replace this in the current application so I hope this gets fixed soon.</p>
<p>In the meanwhile I&#8217;ve filed a bug report at Microsoft Connect (see <a href="https://connect.microsoft.com/VisualStudio/feedback/details/552853/net-4-0-simple-binding-issue?wa=wsignin1.0" target="_blank">here</a>) with sample code that demonstrates the behavior so you can test for yourself. If you do, please vote on Microsoft Connect to get it under their attention!</p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/net/net-4-0-winform-data-binding-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TwitCast</title>
		<link>http://barad-dur.nl/net/twitcast/</link>
		<comments>http://barad-dur.nl/net/twitcast/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 16:28:22 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[LINQ To Twitter]]></category>
		<category><![CDATA[TwitCast]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=147</guid>
		<description><![CDATA[What started it Are you using Twitter? Do you like it or absolutely loathe it? I do like it but one thing I don’t like is constantly checking twitter.com to see if someone tweeted something interesting. So a new idea was born and the wasting of time began. The idea Actually it’s pretty simple, I <a href="http://barad-dur.nl/net/twitcast/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<h3>What started it</h3>
<p>Are you using Twitter? Do you  like it or absolutely loathe it? I do like it but one thing I don’t like is  constantly checking twitter.com to see if someone tweeted something interesting. So  a new idea was born and the wasting of time began.</p>
<h3>The idea</h3>
<p>Actually it’s pretty simple, I  wanted an application that showed a pop-up of some kind that shows me the latest  tweet for a minute or so and then disappear, similar to the new e-mail popup  of Outlook. Another feature I wanted to make is that when I mouse over on  the pop-up the app shows me the last 10 tweets from my timeline.</p>
<h3>Problem #1</h3>
<p>First things first, how to get  the last tweets from Twitter? As all programmers are lazy (see <a href="http://blogoscoped.com/archive/2005-08-24-n14.html">http://blogoscoped.com/archive/2005-08-24-n14.html</a>) I’ve started looking for a library that could do this  for me. Lo’ and behold: <a title="LINQ To Twitter" href="http://linqtotwitter.codeplex.com/" target="_blank">LINQ To Twitter</a>. A wrapper around the Twitter web services written by <a title="Joe Mayo's blog" href="http://geekswithblogs.net/WinAZ/Default.aspx" target="_blank">Joe Mayo</a> (Microsoft  MVP) in C#.</p>
<p>So, problem #1 was solved.</p>
<h3>Problem #2</h3>
<p>The next problem was one of UI.  How to display a nice pop-up that gives access to the rest of the application?  What I wanted to do is create a window that slides in from the top of the  screen when a new Tweet is posted and when the mouse is over it, expand to show the  last 10 tweets. Because a default window border doesn’t look all that nice I’ve  decided to use a transparent window:</p>
<table style="height: 316px;" border="0" cellspacing="0" cellpadding="0" width="700">
<tbody>
<tr>
<td width="307" valign="top"><a href="http://barad-dur.nl/wp-content/uploads/2010/03/twitcast-screen.png" rel="lightbox[147]"><img class="alignnone size-full wp-image-148" title="twitcast-screen" src="http://barad-dur.nl/wp-content/uploads/2010/03/twitcast-screen.png" alt="" width="304" height="191" /></a></td>
<td width="307" valign="top"><strong>XAML:</strong></p>
<pre>&lt;Window

 Background="Transparent"
 AllowsTransparency="True"&gt;
 &lt;Grid&gt;
  &lt;Border&gt;
   &lt;ScrollViewer&gt;
    &lt;ItemsControl /&gt;
   &lt;/ScrollViewer&gt;
  &lt;/Border&gt;
 &lt;/Grid&gt;
&lt;/Window&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p>As you can see it’s a pretty  simple UI but that’s exactly what I wanted. What you see is a transparent Window with a Border and ScrollViewer (the green bit) that hosts an ItemsControl,  nothing fancy so far. The next step was to set the initial position of the  window. A simple RenderTransform took care of that:</p>
<p><strong>XAML:</strong></p>
<pre>&lt;Border.RenderTransform&gt;
&lt;TranslateTransform Y="-360"  /&gt;
&lt;/Border.RenderTransform&gt;
</pre>
<p>The ItemTemplate of the tweets  is also quite straightforward:</p>
<p><strong>XAML:</strong></p>
<pre>&lt;DataTemplate&gt;
  &lt;Border&gt;
    &lt;StackPanel Orientation="Vertical"&gt;
      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Left"&gt;
        &lt;TextBlock Text="{Binding Path=User.Name}" /&gt;
        &lt;TextBlock Text=" at " /&gt;
        &lt;TextBlock Text="{Binding Path=CreatedAt}" /&gt;
      &lt;/StackPanel&gt;
      &lt;TextBlock Text="{Binding Path=Text}" TextWrapping="Wrap" /&gt;
    &lt;/StackPanel&gt;
  &lt;/Border&gt;
&lt;/DataTemplate&gt;
</pre>
<p>The result looks like this:</p>
<p><a href="http://barad-dur.nl/wp-content/uploads/2010/03/image002.jpg" rel="lightbox[147]"><img class="alignnone size-full wp-image-152" title="image002" src="http://barad-dur.nl/wp-content/uploads/2010/03/image002.jpg" alt="" width="375" height="66" /></a></p>
<h3>Fancy UI</h3>
<p>The important part of the  application was to “popup” (or down actually) when a new tweet is available and when the  mouse enters the application so all tweets are shown. To do this three  storyboards are needed:</p>
<p>1.       Animate to the new tweet view</p>
<p>2.       Animate to the full view</p>
<p>3.        Animate to the hidden view</p>
<p>The storyboards all animate the RenderTransform of the Border that hosts the controls.</p>
<p><strong>XAML:</strong></p>
<pre>&lt;Storyboard  x:Key="Hidden"&gt;
  &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="0.4"
    Duration="0:0:0.2" /&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-370"
    Duration="0:0:0.2"
    BeginTime="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
&lt;Storyboard x:Key="NewTweet"&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-295"
    Duration="0:0:0.2" /&gt;
   &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="1"
    Duration="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
&lt;Storyboard x:Key"AllTweets"&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-20"
    Duration="0:0:0.2" /&gt;
  &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="1"
    Duration="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
</pre>
<p>These storyboards are started  by various events in the application. For example: MouseEnter and MouseLeave on the  Border trigger the AllTweets and Hidden Storyboards.</p>
<h3>Timeline</h3>
<p>So far so good, the UI is  basically finished and all that remains is to fill the application with the tweets  from my timeline. For this I’ve created a Timeline class that contains the TwitterContext and a simple timer for the refresh action. The grunt of  this class is the following LINQ statement:</p>
<p><strong>LINQ:</strong></p>
<pre>var statusTweets =
from tweet in  this.context.Status
where tweet.Type == statusType
            &amp;&amp; tweet.ScreenName == this.screenName
            &amp;&amp; tweet.Count == maximumTweetsPerRefresh
            &amp;&amp; tweet.CreatedAt &gt; lastTweetDate
select tweet;
</pre>
<p>This statement will retrieve all tweets from the timeline specified with  screenName that have been created  since the last refresh.  If this results in 1 or more tweets the Timeline class will raise the NewTweetsAvailable event to notify the application that new tweets are  available to display.</p>
<p>The event handler simply pushes the new tweets to the ItemsControl and starts the NewTweet storyboard to  pop-down the window so the latest tweet is visible.</p>
<h3>Wrap up</h3>
<p>As you can see it’s really  simple to build an application that shows the latest tweets in your Twitter timeline. Of  course there are a few features that are missing, for example the storyboards,  but I’ll blog about them a bit later. Be sure to check <a title="TwitCast on Twitter" href="http://twitter.com/#search?q=%23TwitCast" target="_blank">#TwitCast</a> for updates</p>
<p><strong>Update:</strong></p>
<p>TwitCast is now listed on Codeplex at <a title="TwitCast CodePlex project page" href="http://twitcast.codeplex.com/" target="_blank">http://twitcast.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/net/twitcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TFS2010 VSSConverter woes</title>
		<link>http://barad-dur.nl/net/tfs2010-vssconverter-woes/</link>
		<comments>http://barad-dur.nl/net/tfs2010-vssconverter-woes/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 10:12:06 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Team Foundation Server 2010]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VSSConverter]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=134</guid>
		<description><![CDATA[Yesterday I&#8217;ve been busy installing the Beta 2 of Team Foundation Server 2010 to do some testing and to see if we can switch (yay go-live!). And in fact the installing went pretty smooth so the work Microsoft has been doing is really great. Unfortunately when I decided it was time to move our Visual <a href="http://barad-dur.nl/net/tfs2010-vssconverter-woes/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I&#8217;ve been busy installing the Beta 2 of Team Foundation Server 2010 to do some testing and to see if we can switch (yay go-live!). And in fact the installing went pretty smooth so the work Microsoft has been doing is really great.</p>
<p>Unfortunately when I decided it was time to move our Visual Source Safe database to TFS all went sour. The analysis of the VSS database with the VSSConverter tool worked but when I tried to migrate it just sat there and told me:</p>
<p><span>TF60070: Unable to connect to the Team Foundation Server: &#8216;http://ts01:8080/&#8217;. Please ensure that the Team Foundation Server exists and try again.</span></p>
<p><span>At first it seemed logical as the TFS is at http://ts01:8080/<strong>tfs</strong> so no worries there, just a bad config. Unfortunately there is no option in the configuration file to specify a full URL so basically I&#8217;m stuck. (<strong>small update:</strong> I tried to be clever and use URL redirection but it doesn&#8217;t work)<br />
</span></p>
<p><span>I&#8217;ve filed a bug on the <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=500032" target="_blank">Microsoft Connect</a> site so if you&#8217;re having the same problem please vote for it so they&#8217;ll start to fix it.</span></p>
<p><span><strong>Update 1: </strong>It seems that in Beta 1 the VSSConverter tool is unsupported. See the blog post from granth <a href="http://blogs.msdn.com/granth/archive/2009/05/20/visual-studio-team-system-2010-team-foundation-server-beta-1-installation-problems.aspx" target="_blank">here</a>, about half-way on the page</span></p>
<p><span><strong>Update 2: </strong><span style="text-decoration: line-through;">Someone has <a href="http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/de4d9dcc-6140-4f04-a397-c664384f847a" target="_blank">been successful</a> but with the VS2008 version of VSSConverter</span> Nope, he was not.</span></p>
<p><span><strong>Update 3:</strong> Matthew Mitrick (from Microsoft) has a good answer to this. You can read about it <a href="http://social.msdn.microsoft.com/Forums/en-US/tfsprerelease/thread/f4066269-d6b9-4fe0-84a8-ffaf619f0dd4/" target="_blank">here</a>.</span></p>
<p><span>The answer is that in the TFS 2010 Beta 2 there is a new feature called Collections. Unfortunately the documentation of VSSConverter has not been updated as there is a new configuration option to specify in which collection the projects should be migrated. So the solution is to add the option &#8220;</span>collection&#8221; to the TeamFoundationServer element in the options.xml so it looks something like this:</p>
<pre>&lt;TeamFoundationServer name="myserver" port="8080" protocol="http"
collection="tfs/DefaultCollection"&gt;&lt;/TeamFoundationServer&gt;</pre>
<p>If you&#8217;ve installed TFS in another virtual directory than <strong>tfs</strong> you should modify the collection option accordingly. (Goes for the collection as well <img src='http://barad-dur.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/net/tfs2010-vssconverter-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding a WPF DataGridColumn to a LINQ result</title>
		<link>http://barad-dur.nl/net/binding-a-wpf-datagridcolumn-to-a-linq-result/</link>
		<comments>http://barad-dur.nl/net/binding-a-wpf-datagridcolumn-to-a-linq-result/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 14:42:49 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=117</guid>
		<description><![CDATA[I&#8217;ve been tinkering with Visual Studio 2010 Beta1 and the .Net 4 framework. One of the things that I&#8217;ve tried is filling a DataGrid with the results of a LINQ query. Consider the following code: C# var voyages = from voyage in entities.Voyage select new { Number = voyage.Number, ETA = voyage.StartTime }; dataGridTest.ItemsSource = <a href="http://barad-dur.nl/net/binding-a-wpf-datagridcolumn-to-a-linq-result/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tinkering with Visual Studio 2010 Beta1 and the .Net 4 framework. One of the things that I&#8217;ve tried is filling a DataGrid with the results of a LINQ query.<br />
Consider the following code:<br />
<strong>C#</strong></p>
<pre>var voyages = from voyage in entities.Voyage
              select new { Number = voyage.Number, ETA = voyage.StartTime };

dataGridTest.ItemsSource = voyages;</pre>
<p><strong>XAML</strong></p>
<pre>&lt;DataGrid Name="dataGridTest"&gt;
    &lt;DataGrid.Columns&gt;
        &lt;DataGridTextColumn Header="Number" Binding="{Binding Path=Number}" /&gt;
        &lt;DataGridTextColumn Header="ETA" Binding="{Binding Path=ETA}" /&gt;
    &lt;/DataGrid.Columns&gt;
&lt;/DataGrid&gt;</pre>
<p>Seems straightforward enough, doesn&#8217;t it? Well it does but when you try to run it, it&#8217;ll crash and burn with the following exception:</p>
<blockquote><p><strong>InvalidOperationException:</strong> A TwoWay or OneWayToSource binding cannot work on the read-only property &#8216;Number&#8217;</p></blockquote>
<p>The reason that the InvalidOperationException gets thrown is that the Binding used to bind the column to a property is a TwoWay binding, <strong>by default!</strong></p>
<p>But why should (and is) this be a problem? Well, because the result from the LINQ is a new class that contains only get-properties. This is by design because an anonymous type can only contain get-only properties as is written on <a title="MSDN - Anonymous Types" href="http://msdn.microsoft.com/en-us/library/bb397696.aspx" target="_blank">MSDN</a>:</p>
<blockquote><p>Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to first explicitly define a type.</p></blockquote>
<p>There are two workarounds for this problem, one is simply to add <code>Mode=OneWay</code> to the Binding property of the DataGridTextColumn. This will tell the DataGrid (ultimately the Binding) that it should not attempt to write data back to the bound object.</p>
<p>The other workaround is not to use an anonymous type. If you need to be able to change data in the result set this is probably the way to go. By defining a type that contains the properties you want to bind on you can tell LINQ to return that specific type and not an anonymous one.</p>
<p>For example:</p>
<p><strong>C#</strong></p>
<pre>public class VoyageResult {
    public int Number { get; set; }
    public DateTime ETA { get; set; }
}
var voyages = from voyage in entities.Voyage
              select new VoyageResult()
              {
                   Number = voyage.Number,
                   ETA = voyage.StartTime
              };</pre>
<p>voyages will now contain a list of VoyageResults instead of a generated anonymous type (with exactly the same properties!) If you bind this list to the DataGrid it will use the default TwoWay binding without complaints.</p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/net/binding-a-wpf-datagridcolumn-to-a-linq-result/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone, youPhone?</title>
		<link>http://barad-dur.nl/algemeen/iphone-youphone/</link>
		<comments>http://barad-dur.nl/algemeen/iphone-youphone/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 18:42:28 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Algemeen]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=114</guid>
		<description><![CDATA[een beetje vreemd is het wel een microsoft ontwikkelaar die geen windows mobile telefoon heeft. Je zou haast kunnen zeggen dat het heulen met de vijand is. Eigenlijk heeft het nog een doel ook en dat is laten zien dat je zelfs op het Apple platform .Net applicaties kunt bouwen. Eerst maar eens verder spelen <a href="http://barad-dur.nl/algemeen/iphone-youphone/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>een beetje vreemd is het wel een microsoft ontwikkelaar die geen windows mobile telefoon heeft. Je zou haast kunnen zeggen dat het heulen met de vijand is.<br />
Eigenlijk heeft het nog een doel ook en dat is laten zien dat je zelfs op het Apple platform .Net applicaties kunt bouwen.<br />
Eerst maar eens verder spelen voordat ik me daar aan ga wagen.<br />
Oh en voor diegenen die al langer op een berichtje van mij zitten te wachten: eind van het weekend komt er wat aan dus even geduld nog. </p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/algemeen/iphone-youphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
