<?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>JAPF &#187; WPF</title>
	<atom:link href="http://www.japf.fr/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, .Net and modern software development</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:29:32 +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>Attributes-based validation in a WPF MVVM application</title>
		<link>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/</link>
		<comments>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 07:29:32 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=630</guid>
		<description><![CDATA[Today, I&#8217;m proud to share with you my very first article available on CodeProject. This article presents a technique which can be used in order to add validation in a WPF MVVM application based on attribute. Basically, it means that you can write validation logic like that (notice the attribute associated to this property): ?View [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m proud to share with you my very first article available on <a href="http://www.codeproject.com/KB/smart/WPF_Validation_Attribute.aspx">CodeProject</a>. This article presents a technique which can be used in order to add validation in a WPF MVVM application based on attribute. Basically, it means that you can write validation logic like that (notice the attribute associated to this property):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p630code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6302"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p630code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#40;</span>ErrorMessage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Field 'FirstName' is required.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName
<span style="color: #008000;">&#123;</span>
    get
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">firstName</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    set
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">firstName</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnPropertyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FirstName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Of course the article comes with a nice demo application:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/07/02.png" rel="lightbox[630]"><img class="alignnone size-full wp-image-631" title="02" src="http://www.japf.fr/wp-content/uploads/2010/07/02.png" alt="" width="411" height="160" /></a></p>
<p>You can read the full article here: <a href="http://www.codeproject.com/KB/smart/WPF_Validation_Attribute.aspx">Attributes-based validation in a WPF MVVM application</a></p>
<p><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where does the default TwoWay binding comes from ?</title>
		<link>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/</link>
		<comments>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 11:50:43 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[dependency properties]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=620</guid>
		<description><![CDATA[I got a comment on my post about a very simple MVVM application about the fact that removing the TwoWay mode on a binding did not change the behavior of the application. This is a quick occasion for me to share a quick explanation about this. Actually and as you already know if you can [...]]]></description>
			<content:encoded><![CDATA[<p>I got a comment on my post about <a href="http://www.japf.fr/2009/02/very-simple-mvvm-demo-application/">a very simple MVVM application</a> about the fact that removing the TwoWay mode on a binding did not change the behavior of the application. This is a quick occasion for me to share a quick explanation about this.</p>
<p>Actually and as you already know if you can write <em>XAML </em>like <em>Text={Binding &#8230;}</em> it is only because <em>Text </em>is a<em> Dependency Property</em>. Also, dependency properties are defined in a static way (so that if you have 50 textboxes you don&#8217;t have to instantiate 50 times the Text property). The default behavior for the mode of the binding (TwoWay, OneWay, etc.) can be found in the static declaration of the dependency property. For example, in the case of the Text property of the TextBox we have:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p620code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6204"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p620code4"><pre class="csharp" style="font-family:monospace;">TextProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span>
	<span style="color: #666666;">&quot;Text&quot;</span>, 
	<span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">new</span> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>, 
		FrameworkPropertyMetadataOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Journal</span> 
		<span style="color: #008000;">|</span> FrameworkPropertyMetadataOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">BindsTwoWayByDefault</span>,
	<span style="color: #008000;">new</span> PropertyChangedCallback<span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">.</span><span style="color: #0000FF;">OnTextPropertyChanged</span><span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">new</span> CoerceValueCallback<span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceText</span><span style="color: #008000;">&#41;</span>,
	<span style="color: #0600FF; font-weight: bold;">true</span>, 
	UpdateSourceTrigger<span style="color: #008000;">.</span><span style="color: #0000FF;">LostFocus</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The interesting part here if of course the <em>BindsTwoWayByDefault</em> option. Note that this is the only default option available (we can&#8217;t have a OneWayToSource binding by default).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the layout of a WPF TreeView to look like multiple ListBox</title>
		<link>http://www.japf.fr/2010/03/changing-the-layout-of-a-treeview-to-look-like-multiple-listbox/</link>
		<comments>http://www.japf.fr/2010/03/changing-the-layout-of-a-treeview-to-look-like-multiple-listbox/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:31:35 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[listbox]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=457</guid>
		<description><![CDATA[Last week at work I was requested to create a new control which should have the behavior of the WPF treeview with a template involving multiple ListBox. To understand what I mean, I wanted to change the layout of this: To this: Of course, selection must work properly: I asked a question on StackOverflow about [...]]]></description>
			<content:encoded><![CDATA[<p>Last week at work I was requested to create a new control which should have the behavior of the WPF treeview with a template involving multiple ListBox. To understand what I mean, I wanted to change the layout of this:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/03/treeview1.png" rel="lightbox[457]"><img class="alignnone size-full wp-image-459" title="treeview1" src="http://www.japf.fr/wp-content/uploads/2010/03/treeview1.png" alt="" width="121" height="140" /></a></p>
<p>To this:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/03/treeview2.png" rel="lightbox[457]"><img class="alignnone size-full wp-image-460" title="treeview2" src="http://www.japf.fr/wp-content/uploads/2010/03/treeview2.png" alt="" width="342" height="124" /></a></p>
<p>Of course, selection must work properly:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/03/treeview3.png" rel="lightbox[457]"><img class="alignnone size-full wp-image-461" title="treeview3" src="http://www.japf.fr/wp-content/uploads/2010/03/treeview3.png" alt="" width="340" height="124" /></a></p>
<p>I asked a question <a href="http://stackoverflow.com/questions/2369901/change-the-layout-of-a-treeview-to-looks-like-multiple-listbox">on StackOverflow</a> about this control because I didn&#8217;t find any easy way to do it. I though at the beginning that playing with the templates of the TreeView and TreeViewItem would do the trick but it didn&#8217;t.</p>
<p>The solution I finally choose involves creating multiple ListBox and wire them together using DataBinding:</p>
<ul>
<li>I create a new CustomControl which inherits Control (I couldn&#8217;t use neither Selector or TreeView because I wouldn&#8217;t have been able to manage the SelectedItem property from the derived class)</li>
<li>In the template of this CustomControl is an ItemsControl. This ItemsControl has its ItemTemplate property set to a DataTemplate containing a ListBox.</li>
<li>The CustomControl has a Depth property of type int. This property indicates the number of ListBox that should be generated.</li>
<li>The CustomControl automatically databound ListBoxes together: each ListBox&#8217;s ItemsSource property is databound to the SelectedItem&#8217;s children property of the previous ListBox in the visual tree.</li>
<li>The CustomControl has a SelectedItem property and a SelectionChanged event (like Selector-derived class).</li>
<li>I added an IsReallySelected attached property to the ListBoxItem which are generated. This enables to databing an IsSelected property of the ViewModel class behind the control with the IsSelected of the ListBoxItem. I had to create an attached property because its value is true when the ListBoxItem is selected AND the parent ListBox has IsSelectionActive set to true.</li>
</ul>
<p>Here is the result:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/03/control.png" rel="lightbox[457]"><img class="alignnone size-full wp-image-462" title="control" src="http://www.japf.fr/wp-content/uploads/2010/03/control.png" alt="" width="499" height="162" /></a></p>
<p>You can <a href="http://www.japf.fr/wp-content/uploads/2010/03/TestTreeViewList.zip">download the source code</a> of this sample (VS2010 RC solution).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/03/changing-the-layout-of-a-treeview-to-look-like-multiple-listbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF internals part 2 : how the WPF controls are organized ?</title>
		<link>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/</link>
		<comments>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 19:35:32 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[architecture]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=394</guid>
		<description><![CDATA[A couple of weeks ago, I started a series of articles about WPF internals organization. In the first article I did a tour of the core WPF classes. In this second part, I&#8217;m reviewing the organization of the various controls that exist in the framework. Because the image of the diagram is pretty big, I [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago, I started a series of articles about <a href="http://www.japf.fr/wpf-internals/">WPF internals</a> organization. In <a href="http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/">the first article</a> I did a tour of the core WPF classes. In this second part, I&#8217;m reviewing the organization of the various controls that exist in the framework.</p>
<p>Because the image of the diagram is pretty big, I decided to use Silverlight DeepZoom and the result is just below this text <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You can download the <a href="http://www.japf.fr/wp-content/uploads/2010/01/WpfControlsFull.png" target="_blank" rel="lightbox[394]">full image resolution here</a>. Please use the full screen button in the upper right corner of the viewer for the best browsing experience.</p>
<p><script type="text/javascript">
        function onSilverlightError(sender, args) 
        {
            var appSource = "";
            if (sender != null &#038;&#038; sender != 0)
            {
                appSource = sender.getHost().Source;
            }
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;</p>
<p>            var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";</p>
<p>            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";</p>
<p>            if (errorType == "ParserError") 
            {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") 
            {
                if (args.lineNumber != 0) 
                {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }</p>
<p>            throw new Error(errMsg);
        }
</script></p>
<div id="slPluginHost">
		<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="540" height="500"><param name="minRuntimeVersion" value="3.0.40307.0" /><param name="autoUpgrade" value="false" /><param name="source" value="http://www.japf.fr/silverlight/wpfcontrolsexplorer/WpfControlsExplorer.xap"/><param name="onerror" value="onSilverlightError" /><param name="background" value="white" /><param name="initParams" value="adFile=http://www.japf.fr/silverlight/wpfcontrolsexplorer/GeneratedImages" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><br />
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/><br />
            </a><br />
        </object><br />
	<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
<ul></ul>
<p>Here are general remarks that might help you get information from those diagrams.</p>
<p>The top level <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class:</p>
<ul>
<li>Defines general UI properties such as Background, Foreground, BorderBrush and BorderThickness</li>
<li>Defines a set of properties to control font rendering: FontFamily, FontSize, FontStyle&#8230;</li>
<li>Has a DoubleClick event (other mouse events such as MouseUp/MouseDown comes from the UIElement class)</li>
</ul>
<p>Below the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class, we have (this list is not complete):</p>
<ul>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> class: those controls have&#8230; a single Content</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx">ItemsControls</a> class which handles a collection of child controls</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase.aspx">TextBoxBase</a> class which is the parent of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx">TextBox</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">RichTextBox</a></li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.rangebase.aspx">RangerBase</a> class which handles a range (minimum, maximum) and which is the parent of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.scrollbar.aspx">ScrollBar</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.slider.aspx">Slider</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar.aspx">ProgressBar</a> classes</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.thumb.aspx">Thumb</a> class which has the ability to be dragged over a surface</li>
</ul>
<p>Below the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> class we can find many existing WPF controls:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.aspx">ButtonBase</a> and its child: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx">Button</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.aspx">ToggleButton</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.repeatbutton.aspx">RepeatButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx">Label</a> (see <a href="http://joshsmithonwpf.wordpress.com/2007/07/04/differences-between-label-and-textblock/">this post</a> for an explanation of the differences between a Label and a TextBlock)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem.aspx">ListBoxItem</a> and its children: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listviewitem.aspx">ListViewItem</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.comboboxitem.aspx">ComboBoxItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.aspx">ScrollViewer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.headeredcontentcontrol.aspx">HeaderedContentControl</a>, a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> that has both a Content and a Header. This is the case of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.aspx">Expander</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx">GroupBox</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.tabitem.aspx">TabItem</a> controls</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltip.aspx">Tooltip</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.window.aspx">Window</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol.aspx">UserControl</a></li>
</ul>
<p>General other remarks:</p>
<ul>
<li>It&#8217;s funny to see that both Window and UserControl inherits from ContentControl. Before doing the diagram I though that Window came from somewhere else <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
<li>Having those diagrams in mind (or on a screen !) is very useful when you need to create your own custom control</li>
<li>We can see the differences between creating a custom control (inherit from Control or derived class) and a UserControl (inherit from UserControl)</li>
<li>.Net4 will introduce new controls (not in this diagram) in the WPF framework such: DataGrid, Calendar, TimePicker</li>
</ul>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.japf.fr%2f2010%2f01%2fwpf-internals-how-the-wpf-controls-are-organised%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.japf.fr%2f2010%2f01%2fwpf-internals-how-the-wpf-controls-are-organised%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of 2009 blog posts</title>
		<link>http://www.japf.fr/2010/01/review-of-2009-blog-posts/</link>
		<comments>http://www.japf.fr/2010/01/review-of-2009-blog-posts/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 19:01:42 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[resharper]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs2010]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=391</guid>
		<description><![CDATA[In the past year, I&#8217;ve posted more than 30 articles on my blog. Here is a summary of those posts (link in bold are those which got the most traffic during the year). Obviously, MVVM was a very hot topic during 2009 January XAML guidelines: interviews of WPF masters photoSuru: a WPF application with spectacular [...]]]></description>
			<content:encoded><![CDATA[<p>In the past year, I&#8217;ve posted more than 30 articles on my blog. Here is a summary of those posts (link in bold are those which got the most traffic during the year). Obviously, MVVM was a very hot topic during 2009 <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>January</p>
<ul>
<li><a href="http://www.japf.fr/2009/01/xaml-guidelines-interviews-from-wpf-masters/">XAML guidelines: interviews of WPF masters</a></li>
<li><a href="http://www.japf.fr/2009/01/photosuru-a-wpf-application-with-spectacular-user-experience/">photoSuru: a WPF application with spectacular user experience</a></li>
<li><a href="http://www.japf.fr/2009/01/model-view-viewmodel-commands-and-inputbindings/">Model-View-ViewModel, Commands and InputBindings</a></li>
<li><a href="http://www.japf.fr/2009/01/filtering-with-or-without-icollectionview/">Filtering with or without ICollectionView ?</a></li>
<li><a href="http://www.japf.fr/2009/01/why-i-love-linq/">Why do I love Extension Methods in System.Linq ?</a></li>
<li><a href="http://www.japf.fr/2009/01/using-extension-methods-to-raise-an-event/">Using extension methods to raise an event</a></li>
</ul>
<p>February</p>
<ul>
<li><strong><a href="http://www.japf.fr/2009/02/very-simple-mvvm-demo-application/">Very simple MVVM demo application</a></strong></li>
<li><a href="http://www.japf.fr/2009/02/vs2010-ui/">VS2010 UI</a></li>
</ul>
<p>March</p>
<ul>
<li><a href="http://www.japf.fr/2009/03/french-article-about-mvvm-posted/">French article about MVVM posted !</a></li>
<li><strong><a href="http://www.japf.fr/2009/03/thinking-with-mvvm-data-templates-contentcontrol/">Thinking with MVVM: Data Templates + ContentControl</a></strong></li>
<li><a href="http://www.japf.fr/2009/03/mix09-starts-today/">MIX09 starts today !</a></li>
<li><a href="http://www.japf.fr/2009/03/first-look-at-expression-blend-3/">First look at Expression Blend 3 !</a></li>
<li><a href="http://www.japf.fr/2009/03/the-future-of-wpf-at-mix09/">The future of WPF at Mix09</a></li>
</ul>
<p>April</p>
<ul>
<li><a href="http://www.japf.fr/2009/04/adding-transitions-to-a-mvvm-based-dialog/">Adding transitions to a MVVM based dialog</a></li>
</ul>
<p>May</p>
<ul>
<li><a href="http://www.japf.fr/2009/05/browse-your-codebase-like-a-pro-with-resharper/">Browse your codebase like a pro with ReSharper</a></li>
<li><a href="http://www.japf.fr/2009/05/visual-studio-2010-beta1-available-with-net4-and-wpf4-included/">Visual Studio 2010: Beta1 available with .Net4 and WPF4 included</a></li>
<li><a href="http://www.japf.fr/2009/05/net4-wpf4-and-vs2010-interesting-links/">.Net4, WPF4 and VS2010 interesting links</a></li>
</ul>
<p>July</p>
<ul>
<li><a href="http://www.japf.fr/2009/07/beziersegment-demo-application/">BezierSegment demo application</a></li>
</ul>
<p>August</p>
<ul>
<li><a href="http://www.japf.fr/2009/08/learn-how-net-manages-memory-in-15min/">Learn how .Net manages memory in 15min</a></li>
<li><a href="http://www.japf.fr/2009/08/wpf-memory-leak-with-eventmanager-registerclasshandler/">WPF possible memory leak with EventManager.RegisterClassHandler</a></li>
</ul>
<p>September</p>
<ul>
<li><a href="http://www.japf.fr/2009/09/how-to-close-a-view-from-a-viewmodel/">How to close a View from a ViewModel ?</a></li>
</ul>
<p>October</p>
<ul>
<li><a href="http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/">A quick tour of existing MVVM frameworks</a></li>
<li><a href="http://www.japf.fr/2009/10/the-cost-of-building-visual-trees/">The cost of building Visual Trees</a></li>
<li><a href="http://www.japf.fr/2009/10/announcing-the-wpf-internals-series/">Announcing the “WPF internals” series</a></li>
<li><a href="http://www.japf.fr/2009/10/analyzing-events-usage-using-a-resharper-plugin/">Analyzing events usage using a R# plugin</a></li>
<li><strong><a href="http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/">WPF internals part 1 : what are the core WPF classes ?</a></strong></li>
<li><a href="http://www.japf.fr/2009/10/vs2010-beta-2-coming-today/">VS2010 Beta 2 coming today !</a></li>
<li><a href="http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/">How to measure rendering time in a WPF application ?</a></li>
</ul>
<p>November</p>
<ul>
<li><a href="http://www.japf.fr/2009/11/using-snoop-with-vs2010/">Using Snoop to take a look at VS2010 !</a></li>
<li><a href="http://www.japf.fr/2009/11/pdc09-some-announcements/">PDC09: some announcements</a></li>
<li><a href="http://www.japf.fr/2009/11/pdc09-some-wpf-sessions-are-available/">PDC09: some WPF sessions are available !</a></li>
<li><a href="http://www.japf.fr/2009/11/pdc09-wpf-application-performance-tuning/">PDC09: Advanced WPF Application Performance Tuning</a></li>
<li><a href="http://www.japf.fr/2009/11/pdc09-how-vs2010-was-built-with-wpf/">PDC09 : How VS2010 was built with WPF ?</a></li>
<li><strong><a href="http://www.japf.fr/2009/11/discover-compare-existing-mvvm-frameworks/">Discover and compare existing MVVM frameworks !</a></strong></li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;"><strong><a class="row-title" title="Edit “Discover and compare existing MVVM frameworks !”" href="post.php?action=edit&amp;post=369">Discover and compare existing MVVM frameworks !</a></strong></div>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/01/review-of-2009-blog-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discover and compare existing MVVM frameworks !</title>
		<link>http://www.japf.fr/2009/11/discover-compare-existing-mvvm-frameworks/</link>
		<comments>http://www.japf.fr/2009/11/discover-compare-existing-mvvm-frameworks/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 21:31:50 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[silverlifgt]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=369</guid>
		<description><![CDATA[A couple of weeks ago, I wrote a blog post where I compared the existing MVVM frameworks. This post became a bit famous in the WPF/Silverlight blog world and I received a lot of feedback to update the list, fix information, etc. I also got a request from Erik suggesting me to put all the [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago, I wrote <a href="http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/">a blog post</a> where I compared the existing MVVM frameworks. This post became a bit famous in the WPF/Silverlight blog world and I received a lot of feedback to update the list, fix information, etc. I also got a request from Erik suggesting me to put all the datas in a matrix.</p>
<p>Today I&#8217;m proud to announce the <a href="http://www.japf.fr/silverlight/mvvm/index.html">MVVM frameworks Silverlight application</a> (click the image to open the Silverlight3 page).</p>
<p><a href="http://www.japf.fr/silverlight/mvvm/index.html"><img class="alignnone size-full wp-image-370" title="silverlight-mvvm-app" src="http://www.japf.fr/wp-content/uploads/2009/11/silverlight-mvvm-app.png" alt="silverlight-mvvm-app" width="562" height="293" /></a></p>
<p>A couple of observation:</p>
<ul>
<li>please contact me via <a href="http://japf.fr/contact">this blog</a> or <a href="http://www.twitter.com/jalpf">twitter</a> if you find incorrect information</li>
<li>I&#8217;m not judging anybody&#8217;s work by giving rating, it&#8217;s just my personal feeling to have an easiest way to sort the data</li>
</ul>
<p>Hope you&#8217;ll like it <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/11/discover-compare-existing-mvvm-frameworks/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>PDC09 : How VS2010 was built with WPF ?</title>
		<link>http://www.japf.fr/2009/11/pdc09-how-vs2010-was-built-with-wpf/</link>
		<comments>http://www.japf.fr/2009/11/pdc09-how-vs2010-was-built-with-wpf/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 11:24:01 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Stutio]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[pdc]]></category>
		<category><![CDATA[vs2010]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=362</guid>
		<description><![CDATA[In my last blog post, I did a review of a PDC09 Session &#8220;Advanced performance tuning with WPF&#8221;. Today, I&#8217;m doing a review for another very interesting session &#8220;How VS2010 was built with WPF ?&#8221;. The video is available here. Why did Microsoft choose WPF for VS2010 ? Technological: prove the capabilities of WPF4 Architectural [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2009/08/PDC09.jpg" rel="lightbox[362]"><img class="alignnone size-full wp-image-245" title="PDC09" src="http://www.japf.fr/wp-content/uploads/2009/08/PDC09.jpg" alt="PDC09" width="79" height="109" /></a></p>
<p>In my <a href="http://www.japf.fr/2009/11/pdc09-wpf-application-performance-tuning/">last blog post</a>, I did a review of a PDC09 Session &#8220;Advanced performance tuning with WPF&#8221;. Today, I&#8217;m doing a review for another very interesting session &#8220;<strong>How VS2010 was built with WPF</strong> ?&#8221;. The video is available <a href="http://microsoftpdc.com/Sessions/CL09">here</a>.</p>
<p style="text-align: center;"><a href="http://www.japf.fr/wp-content/uploads/2009/11/vs2008tovs2010.png" rel="lightbox[362]"><img class="size-large wp-image-365 aligncenter" title="vs2008tovs2010" src="http://www.japf.fr/wp-content/uploads/2009/11/vs2008tovs2010-1024x361.png" alt="vs2008tovs2010" width="543" height="191" /></a></p>
<p>Why did Microsoft choose WPF for VS2010 ?</p>
<ul>
<li>Technological: prove the capabilities of WPF4</li>
<li>Architectural
<ul>
<li>Separated presentation</li>
<li>Support for long range road map (+10 years)</li>
</ul>
</li>
<li>Key VS2010 features need it: Editor, Architecture Editor, Parallel tools debugging</li>
<li>Take an opportunity to give feedback for WPF4: when VS2010 development started, .Net 3.5 SP1 was just shipped and it was the right time to give feedback for the new features and fixes for WPF4.</li>
</ul>
<p>It is worth noting that VS2010 is a project that is being watched carefully inside Microsoft. We can expect that more Microsoft applications will move to WPF in the next coming years.</p>
<p>What WPF features are used ?</p>
<ul>
<li>Declarative UI using XAML</li>
<li>Databinding</li>
<li>Styles and templates</li>
<li>Application Resources</li>
<li>Interop Win32 (because they did not have the time to rewrite everything using WPF or because features doest not need to use WPF for example de WinForms designer&#8230;)</li>
<li>Integration with the message loop (to deal with particular focus issues)</li>
<li>New text stack (part of WPF4) based on DirectWrite</li>
</ul>
<p>Staged approach</p>
<ul>
<li>Define data models: a huge diagramming and architectural exercice</li>
<li>Replace the main window with WPF (only the window not its content !) to start the mix approach (managed/unmanaged, WPF/Hwnds)</li>
<li>Write new managed components: Window manager, command bar presentation</li>
<li>Scout with other VS teams</li>
<li>Test, Test, Test&#8230;</li>
</ul>
<p>What were the challenges ?</p>
<ul>
<li>Mixed mode application: native and managed code; WPF and HWNDs (Win32 or WinForms)</li>
<li>Keep existing extensions working and allow new extensions to take advantage of WPF</li>
<li>Don&#8217;t &#8220;stop the train&#8221; other teams were working at the same time on the product to add new functionalities</li>
<li>Text clarity</li>
<li>Performance</li>
<li>Focus management</li>
</ul>
<p>You can watch the session <a href="http://microsoftpdc.com/Sessions/CL09">here</a> if you want more detail and demos of what I mention in this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/11/pdc09-how-vs2010-was-built-with-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to measure rendering time in a WPF application ?</title>
		<link>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/</link>
		<comments>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 10:47:20 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[practises]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=325</guid>
		<description><![CDATA[Last week, a colleague of mine asked me an interesting question: &#8220;I&#8217;m filling a control with content and I&#8217;d like to measure the time needed to render my control. How can I do that ?&#8221; The first approach is to measure the elapsed time needed to instantiate and populate the control from C# code. We [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, a colleague of mine asked me an interesting question: &#8220;<em>I&#8217;m filling a control with content and I&#8217;d like to measure the time needed to render my control. How can I do that ?&#8221;</em></p>
<p>The first approach is to measure the elapsed time needed to instantiate and populate the control from C# code. We can use the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx">StopWatch</a> class to have a precise and easy to use measuring tool.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p325code7'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3257"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p325code7"><pre class="csharp" style="font-family:monospace;">Stopwatch sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stopwatch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// here is the operation that fills the control</span>
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">canvas</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Took &quot;</span> <span style="color: #008000;">+</span> sw<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedMilliseconds</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; ms&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>However this approach will not give good results because we&#8217;re not taking into account the time needed to render elements in the visual tree. This is because elements are not rendered when you call the Add methods (for example in a Canvas) but when the visual tree is fully loaded.</p>
<p>A much better approach is to use the Dispatcher and request it to process an action at a priority right bellow the Render priority which is the Loaded priority:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/dispatcherpriority.png" rel="lightbox[325]"><img class="alignnone size-full wp-image-326" title="dispatcherpriority" src="http://www.japf.fr/wp-content/uploads/2009/10/dispatcherpriority.png" alt="dispatcherpriority" width="705" height="188" /></a></p>
<p>Using this trick, we ensure that all rendering actions have been completed. We can use the following code to do that:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p325code8'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3258"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p325code8"><pre class="csharp" style="font-family:monospace;">Stopwatch sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stopwatch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5000</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// here is the operation that fills the control</span>
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">canvas</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Dispatcher</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BeginInvoke</span><span style="color: #008000;">&#40;</span>
  DispatcherPriority<span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span>,
  <span style="color: #008000;">new</span> Action<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Took &quot;</span> <span style="color: #008000;">+</span> sw<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedMilliseconds</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; ms&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Hope this helps !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WPF internals part 1 : what are the core WPF classes ?</title>
		<link>http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/</link>
		<comments>http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 11:04:11 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=309</guid>
		<description><![CDATA[In this first article, I&#8217;d like to make a tour of the core WPF classes and how they are related. Knowing the organization of WPF classes is important when we create a new control because we have to determine which base class we&#8217;re going to use. It is also interesting to know how the framework [...]]]></description>
			<content:encoded><![CDATA[<p>In this first article, I&#8217;d like to make a tour of the core WPF classes and how they are related.</p>
<p>Knowing the organization of WPF classes is important when we create a new control because we have to determine which base class we&#8217;re going to use. It is also interesting to know how the framework has been designed. That&#8217;s the goal of this first article.</p>
<p>Here is an image of the core WPF classes and how they are related (click for larger resolution):</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/WpfClasses.png" rel="lightbox[309]"><img class="alignnone" src="http://www.japf.fr/wp-content/uploads/2009/10/WpfClasses-Preview.png" alt="" width="570" height="735" /></a></p>
<p>The diagram is voluntary simple above the Control classes because that will be targeted by another article.</p>
<div>The top level class <a id="qm:t" title="DispatcherObject" href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherobject.aspx">DispatcherObject</a>:</p>
<ul>
<li>represents an object that is associated with a <a id="ctl00_MTCS_main_ctl02" href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.aspx">Dispatcher</a></li>
<li>can be accessed  from a thread other than the thread the <a id="fa_x" title="DispatcherObject" href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherobject.aspx">DispatcherObject</a> was created on, using <strong>Invoke </strong>or <strong>BeginInvoke </strong>calls</li>
<li>can enforce thread safety  by calling <strong>VerifyAccess</strong></li>
<li><strong>cannot be independently instantiated</strong>; that is, all constructors are protected</li>
</ul>
<p>From the <a id="ccbd" title="DispatcherObject" href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherobject.aspx">DispatcherObject</a> class, we have 4 new classes (one more time, this is a partial view of what really is in the framework):</p>
<ul>
<li>the <a id="rxya" title="FrameworkTemplate" href="http://msdn.microsoft.com/fr-fr/library/system.windows.frameworktemplate.aspx">FrameworkTemplate</a> abstract class, the base class for WPF  <a id="tj4m" title="DataTemplate" href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx">DataTemplate</a>, <a id="susd" title="ControlTemplate" href="http://msdn.microsoft.com/fr-fr/library/system.windows.controls.controltemplate.aspx">ControlTemplate</a> and <a id="h28y" title="ItemsPanelTemplate" href="http://msdn.microsoft.com/fr-fr/library/system.windows.controls.itemspaneltemplate.aspx">ItemsPanelTemplate</a> templates. The <a id="y9uy" title="FrameworkTemplate" href="http://msdn.microsoft.com/fr-fr/library/system.windows.frameworktemplate.aspx">FrameworkTemplate</a> abstract class has a <strong>VisualTree </strong>property (of type <a id="srta" title="FrameworkElementFactory" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelementfactory.aspx">FrameworkElementFactory</a>) to support the creation of the content of the template.</li>
<li>the <a id="n7bs" title="Style" href="http://msdn.microsoft.com/en-us/library/system.windows.style.aspx">Style</a> class that has a collection of <strong>Setters </strong>and <strong>Triggers </strong>that triggers a given <strong>TargetType </strong>and can be <strong>BasedOn </strong>an existing resource</li>
<li>the <a id="zovh" title="DrawingContext" href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext.aspx">DrawingContext</a> class that populates a <a id="ctl00_MTCS_main_ctl56_ctl00_ctl00" href="http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx">Visual</a> or a <a id="ctl00_MTCS_main_ctl56_ctl00_ctl01" href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawing.aspx">Drawing</a> with visual content. <a id="f72b" title="DrawingContext" href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext.aspx">DrawingContext</a> used with a retained mode graphics system (more information <a id="eja7" title="here" href="http://blogs.msdn.com/qiweiye/archive/2008/12/23/retained-mode-graphics-in-wpf.aspx">here</a>)</li>
<li>and the <a id="m9-l" title="DependencyObject" href="index.php?page=stats">DependencyObject</a> class,</li>
</ul>
<p>The <a id="n2rs" title="DependencyObject" href="index.php?page=stats">DependencyObject</a> class:</p>
<ul>
<li>contains the mechanism to deal with <strong>Dependency Properties</strong> through a set of methods such as <strong>ClearValue</strong>, <strong>SetValue</strong> and <strong>GetValue</strong></li>
<li>is inherited by 3 new classes
<ul>
<li><a id="tbd9" title="TriggerBase" href="http://msdn.microsoft.com/en-us/library/system.windows.triggerbase.aspx">TriggerBase</a>, for specifying a conditional value within a <a id="p:.2" href="http://msdn.microsoft.com/en-us/library/system.windows.style.aspx">Style</a> object. Inherited by <a id="s9de" title="DataTrigger" href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx">DataTrigger</a>, <a id="c.a7" title="EventTrigger" href="http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx">EventTrigger</a>&#8230;</li>
<li><a id="x.25" title="Freezable" href="http://msdn.microsoft.com/en-us/library/system.windows.freezable.aspx">Freezable</a>, for object that has a modifiable state and a read-only (frozen) state. Classes that derive from <span>Freezable</span> provide detailed change notification, can be made immutable, and can clone themselves</li>
<li>and the <a id="gjnt" title="Visual" href="http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx">Visual</a> class,</li>
</ul>
</li>
</ul>
<p>The <a id="x0bz" title="Visual" href="http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx">Visual</a> class:</p>
<ul>
<li><strong>provides rendering support</strong> in WPF, which includes <strong>hit testing</strong>, coordinate transformation, and bounding box calculations</li>
<li>is the first class supporting the <strong>VisualParent </strong>property that helps setting up the visual tree</li>
<li>support methods for adding, removing and getting visual child (through the <a id="dpii" title="IAddChild" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">IAddChild</a> interface)</li>
<li>has an <strong>VisualEffect</strong> property of type Effect (from Animatable / Freezable)</li>
<li>is inherited by the <a id="obih" title="UIElement" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">UIElement</a> class,</li>
</ul>
<p>The <a id="tpqv" title="UIElement" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">UIElement</a> class:</p>
<ul>
<li>can render as a child element</li>
<li>contains logic that is used to size and position possible child elements of a <span><a id="egqm" title="UIElement" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">UIElement</a></span> (when interpreted by a layout system)</li>
<li>can respond to user input (including control of where input is getting sent to via their handling of event routing, or routing of commands)</li>
<li>can raise routed events that travel a route through the logical element tree</li>
<li>supports some aspects of the animation system</li>
<li>is enhanced by the <a id="hqop" title="FrameworkElement" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.aspx">FrameworkElement</a> class,</li>
</ul>
<p>The <a id="zm48" title="FrameworkElement" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.aspx">FrameworkElement</a> class extends the <a id="xwrf" title="UIElement" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">UIElement</a> class by adding the following functionalities:</p>
<ul>
<li>layout system definition using the <strong>ArrangeOverride </strong>method</li>
<li>logical tree with the <strong>Parent </strong>property</li>
<li>object lifetime events such as <strong>Initialized</strong>, <strong>Loaded</strong>, <strong>Unloaded</strong></li>
<li>support for databinding (<strong>DataContext </strong>property) and resources management (<strong>Resources </strong>property)</li>
<li>support styles (<strong>Style </strong>property)</li>
<li>does <span style="text-decoration: underline;">not</span> handle the Template feature implemented in the Control class</li>
</ul>
<p>Several classes inherit the <a id="z20a" title="FrameworkElement" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.aspx">FrameworkElement</a> class:</p>
<ul>
<li>the <a id="j9o6" title="Shape" href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.aspx">Shape</a> abstract base class for <a id="ol5e" title="Rectangle" href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.aspx">Rectangle</a>, <a id="s5-b" title="Ellipse" href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.ellipse.aspx">Ellipse</a> and <a id="icdp" title="Polygon" href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon.aspx">Polygon</a> classes</li>
<li>the <a id="bhqw" title="ContentPresenter" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter.aspx">ContentPresenter</a> class to mark where the content should be added when writing <a id="zb:g" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate.aspx">ControlTemplate</a></li>
<li>the <a id="jy7l" title="Adorner" href="http://msdn.microsoft.com/en-us/library/system.windows.documents.adorner.aspx">Adorner</a> class to decorates <a id="ewrx" title="UIElement" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.iaddchild.aspx">UIElement</a></li>
<li>the <a id="x_au" title="Decorator" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.decorator.aspx">Decorator</a> base class, for elements that apply effects onto or around a single child element (such as <a id="l_53" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.border.aspx">Border</a> or <a id="ctl00_MTCS_main_ctl03" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.aspx">Viewbox</a>)</li>
<li>the <a id="a267" title="Panel" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx">Panel</a> class to position and arrange child objects</li>
<li>and the <a id="ufq2" title="Control" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class</li>
</ul>
<p>The <a id="fc2v" title="Control" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class:</p>
<ul>
<li>is the base class for WPF controls that use a <a id="tc:d" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate.aspx">ControlTemplate</a> to define their appearance (through the <strong>Template</strong> property)</li>
<li>defines a set of UI properties (that can be exploited by ControlTemplates): <strong>Background</strong>, <strong>BorderBrush</strong>, <strong>BorderThickness</strong>, <strong>FontFamily</strong>, <strong>FontSize</strong>, <strong>FontStrech</strong>, <strong>FontStyle</strong>, <strong>FontWeight</strong>, <strong>Foreground </strong>and <strong>Padding</strong></li>
<li>support mouse double clicks event using <strong>MouseDoubleClick </strong>and <strong>PreviewMouseDoubleClick</strong></li>
</ul>
<p>In order to show where most of the WPF controls are (but that will be the object of another article), I also added <a id="fo18" title="ContentControl" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a>, <a id="vd9r" title="ItemsControl" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx">ItemsControl</a>, <a id="z-y7" title="UserControl" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol.aspx">UserControl</a> and <a id="zd4e" title="Window" href="http://msdn.microsoft.com/en-us/library/system.windows.window.aspx">Window</a> class to the diagram.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The cost of building Visual Trees</title>
		<link>http://www.japf.fr/2009/10/the-cost-of-building-visual-trees/</link>
		<comments>http://www.japf.fr/2009/10/the-cost-of-building-visual-trees/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 07:36:25 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=268</guid>
		<description><![CDATA[In the current project I&#8217;m working on, I&#8217;m designing a diagramming component. Of course because it&#8217;s for work I can&#8217;t release the source code (however if you want a good starting point you can check out this article). Designing such a component is a challenging task and there are a number of things I learned [...]]]></description>
			<content:encoded><![CDATA[<p>In the current project I&#8217;m working on, I&#8217;m designing a diagramming component. Of course because it&#8217;s for work I can&#8217;t release the source code (however if you want a good starting point you can check out <a href="http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part4.aspx">this article</a>). Designing such a component is a challenging task and there are a number of things I learned during the last few months that I&#8217;m glad to share here.</p>
<p>As you problably know the WPF engine manages 2 trees: the logical tree and the visual tree. For each logical item (that you declare in the XAML), the item is expanded with its visual tree (for example, a scrollbar is made of RepeatButtons and a Thumb). To visualize the visual tree you can use a tool like <a href="http://blois.us/Snoop/">snoop</a>.</p>
<p>In a diagramming tool, you might want to draw lines betweeen entities, like the following:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/connection.png" rel="lightbox[268]"><img class="alignnone size-medium wp-image-270" title="connection" src="http://www.japf.fr/wp-content/uploads/2009/10/connection-300x71.png" alt="connection" width="300" height="71" /></a></p>
<p>In this article, we&#8217;re going to talk about the underlying control that we can use to do that. If you need to create that kind of control, you basically have 2 options:</p>
<ul>
<li>inherits from Control and override the OnRender method to do the basic graphic operations (such as drawing a line or an ellipse)</li>
<li>inherits from Control and create a ControlTemplate to fill the visual tree of your control</li>
</ul>
<p>Of course the first option has better performance, but it&#8217;s also less evolutive. Moreover, in the OnRender method, you can only do low level graphic operations.</p>
<p>Using the second option is generally fine and easy:</p>
<ol>
<li>create the class that inherit from Control</li>
<li>create a style that targets your new control</li>
<li>add a Setter to set the ControlTemplate property</li>
<li>fill the ControlTemplate&#8217;s content</li>
</ol>
<p>Here is a sample ControlTemplate for a basic connection (assuming that the Connection class has 4 double dependency properties (X1,Y1) (X2,Y2) that defines that start and the end point):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p268code10'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26810"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p268code10"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type VisualTreePerf:Connection}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type VisualTreePerf:Connection}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">X1</span>=<span style="color: #ff0000;">&quot;{TemplateBinding X1}&quot;</span> <span style="color: #000066;">Y1</span>=<span style="color: #ff0000;">&quot;{TemplateBinding Y1}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">X2</span>=<span style="color: #ff0000;">&quot;{TemplateBinding X2}&quot;</span> <span style="color: #000066;">Y2</span>=<span style="color: #ff0000;">&quot;{TemplateBinding Y2}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span> <span style="color: #000066;">StrokeThickness</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                                
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Line<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Setter.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Setter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Of course this is a very minimal template, you&#8217;re probable going to improve it by adding new features:</p>
<ul>
<li> 2 rectangles to show the extremities of the connection</li>
<li>2 thumb to be able to drag&#8217;n'drop the extremities</li>
<li>1 context menu to access connection&#8217;s operations</li>
</ul>
<p>You can do that by adding more controls to the template. Now, take a second and think about the performances. Time is needed to built and render the visual tree and the most complex it is, the longer it takes. I did a quick benchmark on my machine and here are the results for 500 connections added in a Canvas:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/10/performance.png" rel="lightbox[268]"><img class="alignnone size-medium wp-image-269" title="performance" src="http://www.japf.fr/wp-content/uploads/2009/10/performance-300x83.png" alt="performance" width="300" height="83" /></a></p>
<p>What we can see is that adding only 5 controls in the template, we multiply the rendering time by 4 ! That means we must be careful when we&#8217;re designing ControlTemplate that are going to be instantiated many time. Before creating the control we should think about whether the control is going to by displayed 1, 10, 100 or 1000 times in our application. More complex ControlTemplates mean more time to render them. Several techniques can be used to improved performance:</p>
<ul>
<li>use a panel that supports UI virtualization (such a VirtualizingStackPanel)</li>
<li>use adorners to give feedback while an item is selected to improve creation performance (create the Adorner only when the item is selected)</li>
</ul>
<p>To explore other performance related techniques:</p>
<ul>
<li> for ItemsControl, make sure to check out Charles Petzold excellent <a href="http://msdn.microsoft.com/en-us/magazine/dd483292.aspx">article on MSDN Magazine</a></li>
<li>for a virtualized canvas, check out <a href="http://blogs.msdn.com/jgoldb/archive/2008/03/08/performant-virtualized-wpf-canvas.aspx">this blog post</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2009/10/the-cost-of-building-visual-trees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
