<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>hardcodet.net</title>
	<link>http://www.hardcodet.net</link>
	<description>code for fame, not fortune</description>
	<pubDate>Wed, 01 Oct 2008 19:41:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>A Debug Activity for Workflow Foundation</title>
		<link>http://www.hardcodet.net/2008/10/wf-debug-activity</link>
		<comments>http://www.hardcodet.net/2008/10/wf-debug-activity#comments</comments>
		<pubDate>Wed, 01 Oct 2008 16:37:24 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[WF]]></category>

		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/10/wf-debug-activity</guid>
		<description><![CDATA[After having worked mostly conceptually for a few months (a detour to enterprise messaging), I&#8217;m back to writing code and getting my hands dirty. And I finally managed to get the time to start playing with Windows Workflow  
To me, learning is all about playing around with the technology, and here&#8217;s a first result [...]]]></description>
			<content:encoded><![CDATA[<p>After having worked mostly conceptually for a few months (a detour to enterprise messaging), I&#8217;m back to writing code and getting my hands dirty. And I finally managed to get the time to start playing with Windows Workflow <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>To me, learning is all about playing around with the technology, and here&#8217;s a first result that I think might be useful for you, too. This WF activity allows you to display an optionally parameterized message via console, debug window, or an assertion:</p>
<ul>
<li><em>Console</em>: The message is displayed via <em>Console.WriteLine()</em> </li>
<li><em>Debug</em>: The message is displayed via <em>Debug.WriteLine()</em> </li>
<li><em>Assert</em>: The message is displayed via <em>Debug.Assert()</em> </li>
</ul>
<p>&#160;</p>
<p>The activity supports binding points for up to 5 parameters and an optional Condition property to suppress output through either declarative or code conditions. The currently selected output mode&#160; is nicely reflected by the designer.</p>
<p>&#160;<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="441" alt="Debug Activities" src="http://www.hardcodet.net/uploads/2008/10/activities1.png" width="496" border="0" /> </p>
<p>Basically, the activity enables you to quickly include debugging tasks into your workflow without leaving the designer. Below is a screenshot of the console output in the <em>ifNegativeActivity</em> branch:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="438" alt="Activity Properties" src="http://www.hardcodet.net/uploads/2008/10/activity-properties1.png" width="495" border="0" /></p>
<p>At runtime, this causes the following output on the console:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="33" alt="console" src="http://www.hardcodet.net/uploads/2008/10/console.png" width="637" border="0" /> </p>
<p>&#160;</p>
<p>The library comes with the above sample, and pretty much demonstrates the different features. The only thing worth mentioning is the use of Conditions:</p>
<ul>
<li>In case of <em>Console</em> or <em>Debug</em> output mode, a condition is not required. However, in case a condition was defined, <strong>the output message</strong>&#160;<strong>will only be displayed if the condition evaluates to <em>true</em></strong>. Otherwise, the activity skips the output. </li>
<li>In case of <em>Assert</em> output mode, the Condition property is mandatory (validated by the designer). Furthermore, in compliance with <em>Debug.Assert</em>, <strong>the output message</strong> <strong>will only be displayed if the condition evaluates to <em>false</em></strong>. </li>
</ul>
<p>&#160;</p>
<p>The activity itself is pretty simple, but it makes a nice addition to my toolbox, especially while I&#8217;m learning. Enjoy <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>Important: Once you opened the sample, you will have to restart VS2008 after the initial build, or the designer won&#8217;t work properly (apparently an issue with the IDE&#8217;s cache)!</em></p>
<p><em></em>    <br />Download (VS2008): <a href="/uploads/2008/10/debug-activity.zip"><strong>debug-activity.zip</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/10/wf-debug-activity/feed</wfw:commentRss>
		</item>
		<item>
		<title>WPF TabControl transition effects with Transitionals</title>
		<link>http://www.hardcodet.net/2008/05/wpf-tab-effects-with-transitionals</link>
		<comments>http://www.hardcodet.net/2008/05/wpf-tab-effects-with-transitionals#comments</comments>
		<pubDate>Tue, 13 May 2008 22:21:16 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<category><![CDATA[WPF Controls]]></category>

		<category><![CDATA[Effects]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/05/wpf-tab-effects-with-transitionals</guid>
		<description><![CDATA[Transitionals is a WPF framework that allows you to integrate nice transition effects into your WPF application with very little effort. It&#8217;s gone live a few days ago on CodePlex and definitely worth checking out:
http://www.codeplex.com/transitionals
&#160;
I&#8217;ve downloaded the library today in order to incorporate a little eye candy into a prototype I&#8217;m doing. However, what I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codeplex.com/transitionals"title="Transitionals on CodePlex"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">Transitionals</a> is a WPF framework that allows you to integrate nice transition effects into your WPF application with <em>very</em> little effort. It&#8217;s gone live a few days ago on CodePlex and definitely worth checking out:</p>
<p><a href="http://www.codeplex.com/transitionals"title="http://www.codeplex.com/transitionals"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">http://www.codeplex.com/transitionals</a></p>
<p>&nbsp;</p>
<p>I&#8217;ve downloaded the library today in order to incorporate a little eye candy into a prototype I&#8217;m doing. However, what I wanted to do was adding transition effects on a tab control, which is currently not supported out of the box by the framework:</p>
<blockquote><p><em>Currently Transitionals ships with only two controls out of the box [&#8230;]. Other controls, like a Tab control for example, could also be created. We encourage the community to come up with other common navigation and presentation scenarios that can leverage transitions.</em></p>
</blockquote>
<p>This sounded like a lot of work, but luckily, it wasn&#8217;t: <em>TabControl</em> provides a <em>ContentTemplate</em> property which can be bound to a data template. This is were I put a <em>TransitionElement</em> control and bound it to the current content of the tab control:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">=&#8221;TabTemplate&#8221;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">t:TransitionElement</span> <span class="attr">Content</span><span class="kwrd">=&#8221;{Binding}&#8221;</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!&#8211; some more stuff &#8211;&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">t:TransitionElement</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>

<span class="rem">&lt;!&#8211; tab control with content template &#8211;&gt;</span>
<span class="kwrd">&lt;</span><span class="html">TabControl</span> <span class="attr">ContentTemplate</span><span class="kwrd">=&#8221;{StaticResource TabTemplate}&#8221;</span> <span class="kwrd">/&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>These bindings take care of everything - a tab switch changes the content of the <em>TransitionElement,</em> which triggers a transition animation. All that was left to do was configuring a transition effect and adding some content to the tab control. Here&#8217;s the complete listing that uses a 3D rotation effect:</p>
<p>&nbsp;</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">Grid.Resources</span><span class="kwrd">&gt;</span>

    <span class="rem">&lt;!&#8211; the data template binds the content to a transition element &#8211;&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">=&#8221;TabTemplate&#8221;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">t:TransitionElement</span> <span class="attr">Content</span><span class="kwrd">=&#8221;{Binding}&#8221;</span><span class="kwrd">&gt;</span>
        <span class="rem">&lt;!&#8211; rotate tab contents &#8211;&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">t:TransitionElement.Transition</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">trans:RotateTransition</span> <span class="attr">Duration</span><span class="kwrd">=&#8221;0:0:1.500&#8243;</span>
                                  <span class="attr">Angle</span><span class="kwrd">=&#8221;90&#8243;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">t:TransitionElement.Transition</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">t:TransitionElement</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>

  <span class="kwrd">&lt;/</span><span class="html">Grid.Resources</span><span class="kwrd">&gt;</span>

  <span class="kwrd">&lt;</span><span class="html">TabControl</span> <span class="attr">ContentTemplate</span><span class="kwrd">=&#8221;{StaticResource TabTemplate}&#8221;</span><span class="kwrd">&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">TabItem</span> <span class="attr">Header</span><span class="kwrd">=&#8221;First&#8221;</span><span class="kwrd">&gt;</span>
      <span class="rem">&lt;!&#8211; some content &#8211;&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">TabItem</span><span class="kwrd">&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">TabItem</span> <span class="attr">Header</span><span class="kwrd">=&#8221;Second&#8221;</span><span class="kwrd">&gt;</span>
     <span class="rem">&lt;!&#8211; some content &#8211;&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">TabItem</span><span class="kwrd">&gt;</span>

  <span class="kwrd">&lt;/</span><span class="html">TabControl</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>My sample contains two tabs which both display the same image. Accordingly, the code snippet above produces the following 3D effect when switching tabs:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="326" alt="transition" src="http://www.hardcodet.net/uploads/2008/05/transition.png" width="344" border="0"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/05/wpf-tab-effects-with-transitionals/feed</wfw:commentRss>
		</item>
		<item>
		<title>Details about upcoming SP1 for VS2008 and .NET 3.5</title>
		<link>http://www.hardcodet.net/2008/05/scottgu-on-sp1-for-vs2008-and-net-3-5</link>
		<comments>http://www.hardcodet.net/2008/05/scottgu-on-sp1-for-vs2008-and-net-3-5#comments</comments>
		<pubDate>Tue, 13 May 2008 07:10:43 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/05/scottgu-on-sp1-for-vs2008-and-net-3-5</guid>
		<description><![CDATA[Scott Guthrie has posted a great summary about the various improvements of the upcoming SP1 for both Visual Studio 2008 and .NET 3.5. No matter what kind of development you&#8217;re currently involved with, there&#8217;s definitely something to be really looking foward to  
A beta is available now, the final release can be expected this [...]]]></description>
			<content:encoded><![CDATA[<p>Scott Guthrie has posted a great summary about the various improvements of the upcoming SP1 for both Visual Studio 2008 and .NET 3.5. No matter what kind of development you&#8217;re currently involved with, there&#8217;s definitely something to be <em>really</em> looking foward to <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>A beta is available now, the final release can be expected this summer. Check out the full post here: <a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx" title="Scott's Blog" onclick="javascript:pageTracker._trackPageview('/outbound/article/weblogs.asp.net');">Scott&#8217;s Blog</a></p>
<p>Regarding WPF, there&#8217;s a more in-depth post by Tim Sneath - check it out here: <a href="http://blogs.msdn.com/tims/archive/2008/05/12/introducing-the-third-major-release-of-windows-presentation-foundation.aspx" title="Tim on WPF improvements" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');">Tim&#8217;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/05/scottgu-on-sp1-for-vs2008-and-net-3-5/feed</wfw:commentRss>
		</item>
		<item>
		<title>A base class for custom WPF binding markup extensions</title>
		<link>http://www.hardcodet.net/2008/04/wpf-custom-binding-class</link>
		<comments>http://www.hardcodet.net/2008/04/wpf-custom-binding-class#comments</comments>
		<pubDate>Wed, 16 Apr 2008 19:56:35 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Data Binding]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/04/wpf-custom-binding-class</guid>
		<description><![CDATA[Already tried to extend the Binding or BindingBase classes in order to write your own custom bindings? And failed because BindingBase.ProvideValue is sealed? Me too&#8230;
The result is a MarkupExtension that works around the issue that you cannot properly extend the Binding class. Basically, it allows you to write binding expressions with the usual syntax without [...]]]></description>
			<content:encoded><![CDATA[<p>Already tried to extend the <em>Binding</em> or <em>BindingBase</em> classes in order to write your own custom bindings? And failed because <em>BindingBase.ProvideValue</em> is sealed? Me too&#8230;</p>
<p>The result is a <em>MarkupExtension</em> that works around the issue that you cannot properly extend the <em>Binding</em> class. Basically, it allows you to write binding expressions with the usual syntax without having to worry about the underlying plumbing. Here&#8217;s a sample binding that adds an additional <em>LookupKey</em> property:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtZipCode&#8221;</span>
         <span class="attr">Text</span><span class="kwrd">=&#8221;{local:LookupExtension Path=ZipCode,
                                      Mode=TwoWay,
                                      UpdateSourceTrigger=PropertyChanged,
                                      LookupKey=F5}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
</div>
<h3>&nbsp;</h3>
<h3>Decorating the Binding class</h3>
<p>As extending the <em>Binding</em> class did not work, I tried a different approach:</p>
<ul>
<li>Create a class that extends <em>MarkupExtension</em> rather than <em>BindingBase</em>. This class provides all the properties that are needed for a binding expression (<em>Source</em>, <em>Path</em>, <em>Converter</em>, &#8230;).
<li>Based on defined binding properties, the extension class internally creates a regular <em>Binding</em> and associates it with the targeted dependency object.</li>
</ul>
<p>I wanted it to look somehow like this (dummy code!):</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> MyCustomExtension : MarkupExtension
{
  <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">object</span> ProvideValue(IServiceProvider provider)
  {
    <span class="rem">//we only use this extension on textboxes</span>
    TextBox tb = GetTextBoxFromProvider(provider);

    <span class="rem">//create a binding and associate it with the text box</span>
    Binding binding = CreateBinding(<span class="kwrd">this</span>.Source, <span class="kwrd">this</span>.Path);
    tb.SetBinding(TextBox.TextProperty, binding);

    <span class="rem">//return a valid value</span>
    <span class="kwrd">return</span> &#8230;;
  }
}</pre>
<p>And guess what - that worked <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The result is an abstract base class that provides pretty much everything you need to create your custom binding classes. The <strong><em>BindingDecoratorBase</em></strong> provides properties for all kinds of binding expressions (<em>Source</em>, <em>Path</em>, <em>Converter</em> etc.) and handles binding creation and association with the targeted dependency object for you:</p>
<p>&nbsp;<img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="480" alt="image" src="http://www.hardcodet.net/uploads/2008/04/image.png" width="490" border="0"> </p>
<p>Basically, the class maintains its own binding class and just forwards the binding statements. For example, here&#8217;s the declaration of the <em>Path</em> property:</p>
<div>
<pre class="csharpcode">[DefaultValue(<span class="kwrd">null</span>)]
<span class="kwrd">public</span> PropertyPath Path
{
  get { <span class="kwrd">return</span> binding.Path; }
  set { binding.Path = <span class="kwrd">value</span>; }
}</pre>
</div>
<div>&nbsp;</div>
<h3>Custom Binding Sample</h3>
<p>Here&#8217;s a simple sample: Let&#8217;s say we have a <em>TextBox</em> that displays the <em>ZipCode</em> property of a bound item. The XAML for this bound control looks like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtZipCode&#8221;</span>
         <span class="attr">Text</span><span class="kwrd">=&#8221;{Binding Path=ZipCode}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
<p>However, we want to interfere with the binding in order to add some additional value. For this example, we&#8217;d like to register the bound control with some kind of handler class. We could also do this with an attached property, but this is more fun <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>First, I created a custom extension called <em>LookupExtension</em> that derives from <em>BindingDecoratorBase</em>. <em>BindingDecoratorBase</em> provides all binding properties out of the box, so the binding expression itself (<em>Path=ZipCode</em>) remains intact. The only thing I had to change in XAML was the extension name and add the custom property for my extension (<em>LookupKey</em>):</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtZipCode&#8221;</span>
         <span class="attr">Text</span><span class="kwrd">=&#8221;{local:LookupExtension Path=ZipCode,
                                      LookupKey=F5}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
<p>As <em>LookupExtension</em> derives from <em>BindingDecoratorBase</em>, it is ensured that in the end, the text box will be bound to the <em>ZipCode</em> property just like with the original regular binding expression.</p>
<p>Below is a first implementation which does not yet add any additional value. Therefore, this extension would behave exactly like the original binding - the <em>ZipCode</em> property of the bound data item is displayed, and updating the TextBox changes the bound property value:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> LookupExtension : BindingDecoratorBase
{
  <span class="rem">//A property that can be set in XAML</span>
  <span class="kwrd">public</span> <span class="kwrd">string</span> LookupKey { get; set; }

  <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">object</span> ProvideValue(IServiceProvider provider)
  {
    <span class="rem">//delegate binding creation etc. to the base class</span>
    <span class="kwrd">return</span> <span class="kwrd">base</span>.ProvideValue(provider);
  }
}</pre>
<p>So what&#8217;s left is adding some custom code to the extension. Below is the complete sample. Basically, the bound control (the text box of the sample) is determined by invoking <em>TryGetTargetItems</em> and then registered with an <em>InputHandler</em>. That&#8217;s it:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> LookupExtension : BindingDecoratorBase
{
  <span class="rem">//A property that can be set in XAML</span>
  <span class="kwrd">public</span> <span class="kwrd">string</span> LookupKey { get; set; }

  <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">object</span> ProvideValue(IServiceProvider provider)
  {
    <span class="rem">//delegate binding creation etc. to the base class</span>
    <span class="kwrd">object</span> val = <span class="kwrd">base</span>.ProvideValue(provider);

    <span class="rem">//try to get bound items for our custom work</span>
    DependencyObject targetObject;
    DependencyProperty targetProperty;
    <span class="kwrd">bool</span> status = TryGetTargetItems(provider, <span class="kwrd">out</span> targetObject,
                                              <span class="kwrd">out</span> targetProperty);

    <span class="kwrd">if</span> (status)
    {
      <span class="rem">//associate an input listener with the control</span>
      InputHandler.RegisterHandler(targetObject, LookupKey);
    }

    <span class="kwrd">return</span> val;
  }
}</pre>
<p>Note the status flag in the snippet above! <em>ProvideValue</em> is also invoked at design time (within Visual Studio). In this case, the <em>provider</em> parameter is null, so be careful to validate your parameters or you&#8217;ll end up with a broken designer.</p>
<p>&nbsp;</p>
<h3>Problem: Attribute syntax with resources</h3>
<p>During the implementation of the sample, I came across an annoying issue: You cannot nest static or dynamic resources within a custom markup extension due to a framework bug. This means that if you wanted to set the <em>Source</em> property explicitly, you could <u>not</u> write it like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtZipCode&#8221;</span>
         <span class="attr">Text</span><span class="kwrd">=&#8221;{local:LookupExtension Source={StaticResource MyAddress}
                                      Path=ZipCode,
                                      LookupKey=F5}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
<p>The above snippet does not compile due to a bug I described <a href="http://www.hardcodet.net/2008/04/nested-markup-extension-bug"title="Nested markup extensions bug"  >here</a>. As a result, you have to fall back to property element syntax if you need to explicitly setting the <em>Source</em> property or other resources (e.g. <em>Converter</em>):</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtZipCode&#8221;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">TextBox.Text</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">local:LookupExtension</span> <span class="attr">Source</span><span class="kwrd">=&#8221;{StaticResource MyAddress}&#8221;</span>
                           <span class="attr">Path</span><span class="kwrd">=&#8221;ZipCode&#8221;</span>
                           <span class="attr">LookupKey</span><span class="kwrd">=&#8221;F5&#8243;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">TextBox.Text</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">TextBox</span><span class="kwrd">&gt;</span></pre>
</p>
<p>&nbsp;</p>
<h3>Source Code / Sample</h3>
<p>I&#8217;ve assembled a simple project that contains the <em>BindingDecoratorBase</em> class and the LookupExtension I used as a sample (VS 2008 project).</p>
<p>You can download it here: <a title="Sample Project" href="/uploads/2008/04/custom-bindings.zip"><strong>custom-bindings.zip</strong></a></p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="327" alt="Markup Extension Sample" src="http://www.hardcodet.net/uploads/2008/04/markup-extension-sample.png" width="420" border="0"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/04/wpf-custom-binding-class/feed</wfw:commentRss>
		</item>
		<item>
		<title>Custom MarkupExtension &#38;&#38; Nested Extensions == Bug</title>
		<link>http://www.hardcodet.net/2008/04/nested-markup-extension-bug</link>
		<comments>http://www.hardcodet.net/2008/04/nested-markup-extension-bug#comments</comments>
		<pubDate>Wed, 16 Apr 2008 17:13:28 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Bugs]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/04/nested-markup-extension-bug</guid>
		<description><![CDATA[I&#8217;m currently working on a custom markup extension and came over a pretty nasty issue. Here&#8217;s the working XAML of a dummy extension:

&#60;TextBox Name=&#8221;txtCity&#8221;
   Foreground=&#8221;{local:ColorExtension Color=Red}&#8221;
/&#62;

&#160;
This works like a charm - the fore color is set to red as expected. However - as soon as I try to set the Color property through [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a custom markup extension and came over a pretty nasty issue. Here&#8217;s the working XAML of a <em>dummy</em> extension:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtCity&#8221;</span>
   <span class="attr">Foreground</span><span class="kwrd">=&#8221;{local:ColorExtension Color=Red}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>This works like a charm - the fore color is set to red as expected. However - as soon as I try to set the <em>Color</em> property through a resource, I&#8217;m getting a compiler error:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtCity&#8221;</span>
   <span class="attr">Foreground</span><span class="kwrd">=&#8221;{local:ColorExtension Color={StaticResource ErrorBrush}}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
</div>
<p>Here&#8217;s the error message: <em>Unknown property &#8216;Color&#8217; for type &#8216;MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension&#8217; encountered while parsing a Markup Extension.</em></p>
<p>&nbsp;</p>
<p>Well, the property does exist. Fortunately, <a href="http://www.beacosta.com"title="Bea's Blog"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.beacosta.com');">Beatriz Costa</a> referred to this bug in her <a href="http://www.beacosta.com/blog/?p=36" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.beacosta.com');">blog</a> - in October <strong>2006</strong>. I&#8217;m working here with VS2008, targeting .NET 3.5, so I can honestly say: I&#8217;m <u>not</u> amused. Fortunately, there&#8217;s a workaround: Skip attribute syntax and fall back to property element syntax:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtCity&#8221;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">TextBox.Foreground</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">local:ColorExtension</span> <span class="attr">Color</span><span class="kwrd">=&#8221;{StaticResource ErrorBrush}&#8221;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">TextBox.Foreground</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">TextBox</span><span class="kwrd">&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>Another solution would be to assign a constructor to the <em>ColorExtension</em> markup extension that takes the Brush as a parameter. In that case, you could write XAML like this:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">=&#8221;txtCity&#8221;</span>
   <span class="attr">Foreground</span><span class="kwrd">=&#8221;{local:ColorExtension {StaticResource ErrorBrush}}&#8221;</span>
<span class="kwrd">/&gt;</span></pre>
</div>
<p>The compiler accepts a <em>StaticResource</em> as a constructor parameter, but it appears it breaks the VS designer. So for now, it&#8217;s property element syntax.</p>
<p>&nbsp;</p>
<p>Some other observations: Some extensions can be nested, others can&#8217;t. Using <em>DynamicResource</em> also fails to compile, while using a <em>RelativeSource</em> statement or something like {x:Null} works without complaints.</p>
<p>If somebody can shed some light on this, I&#8217;ll be happy to update this post accordingly <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/04/nested-markup-extension-bug/feed</wfw:commentRss>
		</item>
		<item>
		<title>WPF TreeView Update</title>
		<link>http://www.hardcodet.net/2008/04/wpf-treeview-update</link>
		<comments>http://www.hardcodet.net/2008/04/wpf-treeview-update#comments</comments>
		<pubDate>Sun, 06 Apr 2008 23:56:04 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[WPF TreeView]]></category>

		<category><![CDATA[Controls]]></category>

		<category><![CDATA[TreeView]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/04/wpf-treeview-update</guid>
		<description><![CDATA[I&#8217;ve posted an update for my WPF TreeView which contains a bugfix and two new  features:

The root item collection is now monitored for changes, and the tree updates  itself automatically. This behaviour, however, can be controlled through the  ObserveRootItems dependency property.
Built-in filtering support through a strongly typed predicate. I&#8217;m not  completely [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve posted an update for my WPF TreeView which contains a bugfix and two new  features:</p>
<ul>
<li>The root item collection is now monitored for changes, and the tree updates  itself automatically. This behaviour, however, can be controlled through the  <em>ObserveRootItems</em> dependency property.</li>
<li>Built-in filtering support through a strongly typed predicate. I&#8217;m not  completely happy with my implementation though - as a matter of fact, I&#8217;ve  already started to rewrite it completely - you can expect the next version within the next 10 days. The filtering API however, will remain  intact.</li>
</ul>
<p>In case you did override some of the tree&#8217;s virtual methods, your project might not compile out of the box because some of these methods now receive additional parameters. However, as nothing has been removed, adjusting your code should be a matter of  seconds.</p>
<p>I&#8217;ve added the download link to the original post:<br />
<a href="http://www.hardcodet.net/2008/01/wpf-treeview" title="TreeView post" >http://www.hardcodet.net/2008/01/wpf-treeview </a></p>
<p>Happy coding <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/04/wpf-treeview-update/feed</wfw:commentRss>
		</item>
		<item>
		<title>Property declaration snippets for ReSharper</title>
		<link>http://www.hardcodet.net/2008/03/resharper-snippet-for-inotifypropertychanged</link>
		<comments>http://www.hardcodet.net/2008/03/resharper-snippet-for-inotifypropertychanged#comments</comments>
		<pubDate>Fri, 21 Mar 2008 13:34:07 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[ReSharper]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Properties]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/03/resharper-snippet-for-inotifypropertychanged</guid>
		<description><![CDATA[Automatic properties in .NET 3.5 are a nice thing, but they are out of the equation if you want to take advantage of the almighty INotifyPropertyChanged interface which plays a crucial role in WPF. Here&#8217;s a set of ReSharper snippets that simplify interface implementation and property declaration.
Event Declaration
The first snippet just prints out an interface [...]]]></description>
			<content:encoded><![CDATA[<p>Automatic properties in .NET 3.5 are a nice thing, but they are out of the equation if you want to take advantage of the almighty <em><strong>INotifyPropertyChanged</strong></em> interface which plays a crucial role in WPF. Here&#8217;s a set of <a href="http://www.jetbrains.com/resharper/"title="ReSharper Homepage"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jetbrains.com');">ReSharper</a> snippets that simplify interface implementation and property declaration.</p>
<h3>Event Declaration</h3>
<p>The first snippet just prints out an interface implementation and adds some additional value to it, including a runtime check of property names in Debug builds (credits go to <a href="http://joshsmithonwpf.wordpress.com/2007/08/29/a-base-class-which-implements-inotifypropertychanged/" onclick="javascript:pageTracker._trackPageview('/outbound/article/joshsmithonwpf.wordpress.com');">Josh Smith</a> for this one). Just type <em>inpc</em> to print out this statement:</p>
<div>
<pre class="csharpcode"><span class="preproc">#region</span> INotifyPropertyChanged <span class="kwrd">event</span>

<span class="rem">///&lt;summary&gt;</span>
<span class="rem">///Occurs when a property value changes.</span>
<span class="rem">///&lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">event</span> PropertyChangedEventHandler PropertyChanged;

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Raises the &lt;see cref=&#8221;PropertyChanged&#8221;/&gt; event for</span>
<span class="rem">/// a given property.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&#8221;propertyName&#8221;&gt;The name of the changed property.&lt;/param&gt;</span>
<span class="kwrd">protected</span> <span class="kwrd">void</span> OnPropertyChanged(<span class="kwrd">string</span> propertyName)
{
  <span class="rem">//validate the property name in debug builds</span>
  VerifyProperty(propertyName);

  <span class="kwrd">if</span> (PropertyChanged != <span class="kwrd">null</span>)
  {
    PropertyChanged(<span class="kwrd">this</span>, <span class="kwrd">new</span> PropertyChangedEventArgs(propertyName));
  }
}

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Verifies whether the current class provides a property with a given</span>
<span class="rem">/// name. This method is only invoked in debug builds, and results in</span>
<span class="rem">/// a runtime exception if the &lt;see cref=&#8221;OnPropertyChanged&#8221;/&gt; method</span>
<span class="rem">/// is being invoked with an invalid property name. This may happen if</span>
<span class="rem">/// a property&#8217;s name was changed but not the parameter of the property&#8217;s</span>
<span class="rem">/// invocation of &lt;see cref=&#8221;OnPropertyChanged&#8221;/&gt;.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&#8221;propertyName&#8221;&gt;The name of the changed property.&lt;/param&gt;</span>
[Conditional(<span class="str">&#8220;DEBUG&#8221;</span>)]
<span class="kwrd">private</span> <span class="kwrd">void</span> VerifyProperty(<span class="kwrd">string</span> propertyName)
{
  Type type = <span class="kwrd">this</span>.GetType();

  <span class="rem">//look for a *public* property with the specified name</span>
  PropertyInfo pi = type.GetProperty(propertyName);
  <span class="kwrd">if</span> (pi == <span class="kwrd">null</span>)
  {
    <span class="rem">//there is no matching property - notify the developer</span>
    <span class="kwrd">string</span> msg = <span class="str">&#8220;OnPropertyChanged was invoked with invalid property name {0}: &#8220;</span>;
    msg += <span class="str">&#8220;{0} is not a public property of {1}.&#8221;</span>;
    msg = String.Format(msg, propertyName, type.FullName);
    Debug.Fail(msg);
  }
}

<span class="preproc">#endregion</span></pre>
</div>
<p>&nbsp;</p>
<p>&#8230;and don&#8217;t forget to declare the <em>INotifyPropertyChanged</em> implementation. The snippet won&#8217;t do that for you:</p>
<div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Class1 : INotifyPropertyChanged</pre>
</div>
<p>&nbsp;</p>
<h2>Property Declaration</h2>
<p>The second snippet (shortcut is <em>pcp</em>) simplifies the declaration of a given property for you. You can define property name, type, default value and a description summary. The generated code for a sample property looks like this:</p>
<div>
<pre class="csharpcode"><span class="preproc">#region</span> UserId

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// The numeric ID of the user. Defaults to null.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">private</span> <span class="kwrd">int</span>? userId = <span class="kwrd">null</span>;

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// The numeric ID of the user. Defaults to null.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">int</span>? UserId
{
  get { <span class="kwrd">return</span> userId; }
  set
  {
    <span class="rem">//ignore if values are equal</span>
    <span class="kwrd">if</span> (<span class="kwrd">value</span> == userId) <span class="kwrd">return</span>;

    userId = <span class="kwrd">value</span>;
    OnPropertyChanged(<span class="str">&#8220;UserId&#8221;</span>);
  }
}

<span class="preproc">#endregion</span></pre>
</div>
<p>&nbsp;</p>
<p>Grab the snippet here: <a title="Download snippet file" href="/uploads/2008/03/rs_properties.xml">Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/03/resharper-snippet-for-inotifypropertychanged/feed</wfw:commentRss>
		</item>
		<item>
		<title>WPF is for LOB - and we can even do RAD (WTF?)</title>
		<link>http://www.hardcodet.net/2008/03/wpf-ready-for-lob</link>
		<comments>http://www.hardcodet.net/2008/03/wpf-ready-for-lob#comments</comments>
		<pubDate>Tue, 18 Mar 2008 14:55:04 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/03/wpf-ready-for-lob</guid>
		<description><![CDATA[Agreed - the WPF learning curve is steep, but once one figures out how the basics work, things tend to get amazingly easy. And of course, the emerging sets of toolkits dont&#8217;t hurt either.
Here&#8217;s another sample - a customer of mine needed a utility to maintain data in their web shop (MySql) and update the [...]]]></description>
			<content:encoded><![CDATA[<p>Agreed - the WPF learning curve is steep, but once one figures out how the basics work, things tend to get amazingly easy. And of course, the emerging sets of toolkits dont&#8217;t hurt either.</p>
<p>Here&#8217;s another sample - a customer of mine needed a utility to maintain data in their web shop (MySql) and update the shop database based on external data. Here&#8217;s the result of about 1.5 days work, starting pretty much from scratch (click on thumbnail for the screenshot):</p>
<p><a href="http://www.hardcodet.net/uploads/2008/03/pw-shopadmin1.png" ><img src="http://www.hardcodet.net/uploads/2008/03/pw-shopadmin-thumb1.png" style="border: 0px none " alt="pw_shopadmin" border="0" height="133" width="244" /></a></p>
<p>And once more, I have to say: <a href="http://www.llblgen.com" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.llblgen.com');">LLBLGen</a> ist a wonderful tool - setting up database mappings is a breeze, and the generated entities play <strong>very</strong> nice with WPF. Kudos to Frans Bourma for this one!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/03/wpf-ready-for-lob/feed</wfw:commentRss>
		</item>
		<item>
		<title>A WPF File Selection control</title>
		<link>http://www.hardcodet.net/2008/03/wpf-file-selection-control</link>
		<comments>http://www.hardcodet.net/2008/03/wpf-file-selection-control#comments</comments>
		<pubDate>Fri, 14 Mar 2008 00:13:48 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF Controls]]></category>

		<category><![CDATA[Controls]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/03/wpf-file-selection-control</guid>
		<description><![CDATA[&#160; 
This is a pretty simple user control, which allows you to display a file dialog to open or save files. Its look can be easily adjusted, and it provides built-in truncation of the file string to a predefined length if necessary. Here&#8217;s the XAML for the above sample control:

&#60;files:FileSelector x:Name=&#8221;openFileSelector&#8221;
     [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="102" alt="fileselector" src="http://www.hardcodet.net/uploads/2008/03/fileselector.png" width="451" border="0"> </p>
<p>This is a pretty simple user control, which allows you to display a file dialog to open or save files. Its look can be easily adjusted, and it provides built-in truncation of the file string to a predefined length if necessary. Here&#8217;s the XAML for the above sample control:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">files:FileSelector</span> <span class="attr">x:Name</span><span class="kwrd">=&#8221;openFileSelector&#8221;</span>
                    <span class="attr">Mode</span><span class="kwrd">=&#8221;Open&#8221;</span>
                    <span class="attr">MaxDisplayLength</span><span class="kwrd">=&#8221;50&#8243;</span>
                    <span class="attr">Height</span><span class="kwrd">=&#8221;24&#8243;</span>
                    <span class="attr">Width</span><span class="kwrd">=&#8221;400&#8243;</span> <span class="kwrd">/&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>The <em>TextBlock</em> in the screenshot which displays the full file path was simply bound to the control&#8217;s <em>FileName</em> dependency property:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">=&#8221;{Binding ElementName=openFileSelector, Path=FileName}&#8221;</span> <span class="kwrd">/&gt;</span></pre>
</div>
<p>&nbsp;</p>
<p>The control does not provide too many extension or styling points - the idea is that you just copy it into your solution, adjust the styling of the control&#8217;s contents (Border, Button etc.) and be on your way. The source comes with a small sample project - enjoy <img src='http://www.hardcodet.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a title="Download source with sample project." href="/uploads/2008/03/fileselector.zip">Download Control</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/03/wpf-file-selection-control/feed</wfw:commentRss>
		</item>
		<item>
		<title>New Blendables</title>
		<link>http://www.hardcodet.net/2008/03/blendables-licensing</link>
		<comments>http://www.hardcodet.net/2008/03/blendables-licensing#comments</comments>
		<pubDate>Thu, 06 Mar 2008 19:50:55 +0000</pubDate>
		<dc:creator>Philipp Sumi</dc:creator>
		
		<category><![CDATA[WPF Controls]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.hardcodet.net/2008/03/blendables-licensing</guid>
		<description><![CDATA[Just saw that Blendables have extended their portfolio of WPF controls. The stuff looks good, but unfortunately, their licensing scheme doesn&#8217;t:
A license is required for each machine utilizing the blendables controls. [&#8230;] As we do not offer a deactivation method, if you must reactivate on a new developer machine you are allowed up to 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Just saw that <a href="http://www.blendables.com/"title="http://www.blendables.com/"  onclick="javascript:pageTracker._trackPageview('/outbound/article/www.blendables.com');">Blendables</a> have extended their portfolio of WPF controls. The stuff looks good, but unfortunately, their licensing scheme doesn&#8217;t:</p>
<blockquote><p><em>A license is required for each machine utilizing the blendables controls. [&#8230;] As we do not offer a deactivation method, if you must reactivate on a new developer machine you are allowed up to 3 activations. This is for the case of re-imaging or setting up a new developer machine. Once this limit is reached you must contact blendables support at [&#8230;] to proceed with activation.</em></p>
</blockquote>
<p>I must say, <em><u>not</u></em> purchasing their product is a no-brainer&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hardcodet.net/2008/03/blendables-licensing/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
