<?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>FormatException &#187; .Net 4.0</title>
	<atom:link href="http://www.formatexception.com/tag/net-4-0/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.formatexception.com</link>
	<description>Ramblings on developing in the Windows World</description>
	<lastBuildDate>Mon, 24 May 2010 15:43:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Upgrading/Migrating to .net 4.0, two gotcha&#8217;s I found</title>
		<link>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/</link>
		<comments>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/#comments</comments>
		<pubDate>Mon, 24 May 2010 15:04:11 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.Net 4.0]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=274</guid>
		<description><![CDATA[Recently while upgrading a large project to .net 4.0 we ran into two problems.  The first was simply that none of our xaml dictionaries were styling anything.  The second was that all of our images looked horrible.  These two problems aren&#8217;t mentioned anywhere by Microsoft in their guide to migrating to .net [...]]]></description>
			<content:encoded><![CDATA[<p>Recently while upgrading a large project to .net 4.0 we ran into two problems.  The first was simply that none of our xaml dictionaries were styling anything.  The second was that all of our images looked horrible.  These two problems aren&#8217;t mentioned anywhere by Microsoft in <a href='http://msdn.microsoft.com/en-us/library/ee941656.aspx'>their guide to migrating to .net 4.0</a>.</p>
<p>The first problem relates to merged dictionaries within a dictionary.  In our project we have a master dictionary in a common project.  All other projects call this common project.  The common project contains only the xaml resource dictionaries.  Our main dictionary looks kind of like:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>Virtually every element in our application is styled via this dictionary.  This creates a clean set of styles in seperate files that makes maintenance of these really simple.  The problem is that in .net 4.0 none of the styles in these dictionaries were being applied.  It seemed like .net 4.0 just wouldn&#8217;t go down into the resource dictionaries and get the proper styles.  After posting <a href='http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f1231b5c-9fd2-40b7-8398-ebf7af8c0d2f/#c9f8b070-1e0f-4865-9c4f-72812ad8b906'>a question in the msdn forums</a> I took a look around Connect (Microsoft&#8217;s listing of bugs) and <a href='https://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references#'>found that someone else had the same problem</a>.  </p>
<p>Fortunately one of the MSDN moderators came to my rescue and posted a workaround.  Oddly enough all you have to do is include an empty style after the merged dictionary and everything starts working again.  Our new master resource dictionary looks something like:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
   &lt;Style TargetType="{x:Type Window}"/&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>and now all cascading styles are being applied correctly.</p>
<p>The second problem has to do resizing and scaling of images.  Once again <a href='http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76398b1c-4d56-4601-ad11-c2e4636f62ba'>I started with a post on MSDN forums</a> and then went <a href='https://connect.microsoft.com/VisualStudio/feedback/details/550163/bitmapscalingmode-default-has-changed-from-highquality-to-lowquality'>and took a look around connect</a> (I really should begin starting at Connect).  It seems that in .net 4.0 in order to increase the effeciency of everything they changed the default rendering of images from Fant (extremely high quality) to Low quality.  Not finding any easy solutions I simply changed our master resource dictionary from as show above to:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
   &lt;Style TargetType="{x:Type Window}"/&gt;
       &lt;!--Fix for images rendering in low quality--&gt;
   &lt;Style TargetType="{x:Type Image}"&gt;
      &lt;Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality"/&gt;
   &lt;/Style&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>so that images would always defualt to rendering in High Quality.  After I created this solution someone posted as a workaround in Connect just to add:</p>
<pre name="code" class="csharp">RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality);
</pre>
<p>to the constructor of your main window and this will inherit to all images by default.  I haven&#8217;t tried this solution and I&#8217;m not sure what would happen if you have projects other than the main project that open their own windows.  It would seem like this should be a global setting since you&#8217;re setting the static in RenderOptions and this should work fine.  For us this was unneeded since every window in all our projects calls the xaml shown above.</p>
<p>Well, if we run into anything else I&#8217;ll post it here but these were the only two issues we&#8217;ve found so far.  It&#8217;s been a big benefit to upgrade for us to .net 4.0 if for no other reason then to have Parallel.For and Parallel.ForEach.</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;title=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found&amp;bodytext=Recently%20while%20upgrading%20a%20large%20project%20to%20.net%204.0%20we%20ran%20into%20two%20problems.%20%20The%20first%20was%20simply%20that%20none%20of%20our%20xaml%20dictionaries%20were%20styling%20anything.%20%20The%20second%20was%20that%20all%20of%20our%20images%20looked%20horrible.%20%20These%20two%20problems%20aren%27t%20mentione" title="Digg"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;t=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;title=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="DotNetKicks"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/dotnetkicks.png" title="DotNetKicks" alt="DotNetKicks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;title=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found&amp;annotation=Recently%20while%20upgrading%20a%20large%20project%20to%20.net%204.0%20we%20ran%20into%20two%20problems.%20%20The%20first%20was%20simply%20that%20none%20of%20our%20xaml%20dictionaries%20were%20styling%20anything.%20%20The%20second%20was%20that%20all%20of%20our%20images%20looked%20horrible.%20%20These%20two%20problems%20aren%27t%20mentione" title="Google Bookmarks"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;title=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="Live"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;t=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.Net 4.0 stuff on the way.</title>
		<link>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/</link>
		<comments>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:51:21 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.Net 4.0]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=256</guid>
		<description><![CDATA[Here&#8217;s some nice .Net 4.0 stuff on the way.  I&#8217;ve been working on some poker tournament software with a lot of the new 4.0 features in mind.  Once I have a couple of posts ready I&#8217;ll throw them up.
Thanks,
Brian



Share and Enjoy:


	
	
	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some <a href="http://jyotsnakalambe.wordpress.com/2009/08/14/new-release-net-framework-4-0-features/">nice .Net 4.0 stuff on the way</a>.  I&#8217;ve been working on some poker tournament software with a lot of the new 4.0 features in mind.  Once I have a couple of posts ready I&#8217;ll throw them up.</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;title=.Net%204.0%20stuff%20on%20the%20way.&amp;bodytext=Here%27s%20some%20nice%20.Net%204.0%20stuff%20on%20the%20way.%20%20I%27ve%20been%20working%20on%20some%20poker%20tournament%20software%20with%20a%20lot%20of%20the%20new%204.0%20features%20in%20mind.%20%20Once%20I%20have%20a%20couple%20of%20posts%20ready%20I%27ll%20throw%20them%20up.%0D%0A%0D%0AThanks%2C%0D%0ABrian" title="Digg"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;t=.Net%204.0%20stuff%20on%20the%20way." title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;title=.Net%204.0%20stuff%20on%20the%20way." title="DotNetKicks"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/dotnetkicks.png" title="DotNetKicks" alt="DotNetKicks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;title=.Net%204.0%20stuff%20on%20the%20way.&amp;annotation=Here%27s%20some%20nice%20.Net%204.0%20stuff%20on%20the%20way.%20%20I%27ve%20been%20working%20on%20some%20poker%20tournament%20software%20with%20a%20lot%20of%20the%20new%204.0%20features%20in%20mind.%20%20Once%20I%20have%20a%20couple%20of%20posts%20ready%20I%27ll%20throw%20them%20up.%0D%0A%0D%0AThanks%2C%0D%0ABrian" title="Google Bookmarks"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;title=.Net%204.0%20stuff%20on%20the%20way." title="Live"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;t=.Net%204.0%20stuff%20on%20the%20way." title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
