<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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>wpf &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/wpf/</link>
	<description>Feed of posts on WordPress.com tagged "wpf"</description>
	<pubDate>Mon, 30 Nov 2009 07:48:37 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[WPF AddIns with late binding]]></title>
<link>http://freozz.wordpress.com/2009/11/30/wpf-addins-with-late-binding/</link>
<pubDate>Mon, 30 Nov 2009 06:04:39 +0000</pubDate>
<dc:creator>freozz</dc:creator>
<guid>http://freozz.wordpress.com/2009/11/30/wpf-addins-with-late-binding/</guid>
<description><![CDATA[This is a simplistic solution to load user controls by late binding with the use of reflection. Imag]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is a simplistic solution to load user controls by late binding with the use of reflection. Imagine that you have a main WPF application and need to load AddIns or Plugins to this application after the application has been started. This means early binding will not work, ie adding a reference to the project before compiling. To solve this reflection can be useful and a simple example with source code will be shown. This solution only supports load and does not support unload. What is presented is mereley a proof-of concept to load a .dll from an applicatin without having to reference that dll when the application was built.</p>
<p>Three projects will be used in this example, the application and two AddIns. Start with creating the AddIns. In this case I created two projects of type User Control Library and named them AddIn1 and AddIn2. For this example the AddIns are only a label:</p>
<p>&#60;UserControl x:Class=&#8221;AddIn1.AddIn&#8221;<br />
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;<br />
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;<br />
Height=&#8221;Auto&#8221; Width=&#8221;Auto&#8221;&#62;<br />
&#60;Label Content=&#8221;AddIn1&#8243; FontSize=&#8221;20&#8243; Foreground=&#8221;Red&#8221;/&#62;<br />
&#60;/UserControl&#62;</p>
<p>&#60;UserControl x:Class=&#8221;AddIn1.AddIn&#8221;<br />
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;<br />
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;<br />
Height=&#8221;Auto&#8221; Width=&#8221;Auto&#8221;&#62;<br />
&#60;Label Content=&#8221;AddIn1&#8243; FontSize=&#8221;20&#8243; Foreground=&#8221;Red&#8221;/&#62;<br />
&#60;/UserControl&#62;</p>
<p>To both this projec I added a class called WPFAddIn with only one method:</p>
<p>public class WPFAddIn<br />
{<br />
public FrameworkElement GetAddInUI()<br />
{<br />
return new AddIn();<br />
}<br />
}</p>
<p>Thats all needed for the plugin. Now to the main application. Create and WPF Application, I named it to WPFLateBinding. In the window make a simple layout with a StackPanel and two buttons.</p>
<p>&#60;Window x:Class=&#8221;WPFLateBinding.Window1&#8243;<br />
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;<br />
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;<br />
Title=&#8221;Window1&#8243; Height=&#8221;300&#8243; Width=&#8221;300&#8243;&#62;<br />
&#60;StackPanel Name=&#8221;_stackPanel&#8221;&#62;<br />
&#60;StackPanel Orientation=&#8221;Horizontal&#8221;&#62;<br />
&#60;Button Content=&#8221;Load AddIn1&#8243; Click=&#8221;Button_Click&#8221;/&#62;<br />
&#60;Button Content=&#8221;Load AddIn2&#8243; Click=&#8221;Button_Click_1&#8243;/&#62;<br />
&#60;/StackPanel&#62;<br />
&#60;/StackPanel&#62;<br />
&#60;/Window&#62;</p>
<p>&#160;</p>
<p>Implement the EventHandlers for the button clicks:</p>
<p>private void Button_Click(object sender, RoutedEventArgs e)<br />
{<br />
loadAddIn(@&#8221;..\..\..\AddIn1\bin\Debug\AddIn1.dll&#8221;);<br />
}</p>
<p>private void Button_Click_1(object sender, RoutedEventArgs e)<br />
{<br />
loadAddIn(@&#8221;..\..\..\AddIn2\bin\Debug\AddIn2.dll&#8221;);<br />
}</p>
<p>As you can see a loadAddIn method is being called with a path to a compiled dll. The implementation of loadAddIn looks like this:</p>
<p>void loadAddIn(string path)<br />
{<br />
MethodInfo mi;<br />
object result = null;</p>
<p>try<br />
{<br />
Assembly assemblyInstance = Assembly.LoadFrom(path);</p>
<p>Type[] types = assemblyInstance.GetTypes();<br />
foreach (Type t in types)<br />
{<br />
mi = t.GetMethod(&#8220;GetAddInUI&#8221;);<br />
if (mi != null)<br />
{<br />
string typeName = t.FullName;<br />
object lateBoundObj = assemblyInstance.CreateInstance(typeName);<br />
result = t.InvokeMember(&#8220;GetAddInUI&#8221;, BindingFlags.Public &#124; BindingFlags.InvokeMethod &#124; BindingFlags.Instance, null, lateBoundObj, null);<br />
break;<br />
}<br />
}</p>
<p>_stackPanel.Children.Add(result as FrameworkElement);<br />
}<br />
catch (Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
}</p>
<p>The loadAddIn method opens the dll and performs a search for the &#8220;GetAddInUI&#8221; method in the types of the assembly. If found the method is invoked and the result is casted to a FrameworkElement.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Windows Presentation Foundation - confused and frustrated]]></title>
<link>http://softhell.wordpress.com/2009/11/30/windows-presentation-foundation-confused-and-frustrated/</link>
<pubDate>Mon, 30 Nov 2009 02:45:21 +0000</pubDate>
<dc:creator>idevelop4food</dc:creator>
<guid>http://softhell.wordpress.com/2009/11/30/windows-presentation-foundation-confused-and-frustrated/</guid>
<description><![CDATA[While going through the design phase of our new in-house enterprise-level application, one of the to]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>While going through the design phase of our new in-house enterprise-level application, one of the topics our team touched upon is whether we should look into WPF. I think the idea was compeling and besides, it&#8217;s always nice to jump into something new. I had some time to mess around with WPF and i have to admit, the things that i don&#8217;t like about it are piling up by the hour.</p>
<p><strong>WPF roadmap</strong></p>
<p>My biggest question is whether WPF will actually replace WinForms. The lack of definite answer from Microsoft leads me to think that this is probably what&#8217;s going to happen when the framework matures. I have read a few blogs where some folks suggest otherwise. However, I just don&#8217;t see a reason why you would consider supporting WinForms when you have something much superior and flexible to offer. Aside from that, what&#8217;s stopping Microsoft from screwing a major part of their community developing in WinForms. They&#8217;ve already done it with Web Service Enhancements and its support in Visual Studio 2008. VS 2008 itself was pretty much abandoned after the first service pack release, and according to <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=498237" target="_blank">this</a>, we can all suck a big fat one because Microsoft sees more value in getting your benjamins for new licenses of VS 2010 than actually releasing a new service pack for potentially one of the worst Visual Studio releases. (if it isn&#8217;t the worst, it&#8217;s probably up there with the shitty ones)</p>
<p><strong>Flashy design or back to WinForms?<br />
</strong></p>
<p>There is no doubt that WPF is a good enhancement to software design process. It&#8217;s a powerful framework and with power comes complexity. Unfortunately, managing that complexity comes at a significant expense. You can either screw around with the XML markup that generates trendy UI or you can get Expression Blend and screw with it, which adds another layer of complexity on its own. Your other option is, of course, to hire a good UI designer who&#8217;s not only familiar with all of the tools necessary to work with the framework, but who can also do some design, animation programming and etc. I don&#8217;t know what the statistic is for software companies hiring graphics designers, but i have yet to work for one which actually did. Besides, considering how new this technology is, I can only wonder how difficult it would be to fill such a position.</p>
<p><strong>Working with Expression Blend</strong></p>
<p>My exposure with Blend was very limited and frustrating. I&#8217;ve had the chance to work with Expression Blend 2, which appears to be out of date since the version 3 is out already. I&#8217;m sure a lot of folks worked with Photoshop and its intuitive UI. It seemed much of Blend interface is borrowed from Photoshop, which at first was a great indicator. However, working with the application revealed that it is a new charlie foxtrot from Microsoft. I played around with a few features and tried what i thought was going to be an easy task &#8211; adding background image to a rectangle. I spent an hour attempting to do this and got absolutely nowhere. As was explained in this <a href="http://www.ikriv.com/blog/?p=206" target="_blank">article</a>, performing such a simple task is completely counter-intuitive. At this point, i had absolutely no doubt in my mind that this wasn&#8217;t going to go anywhere, and off this hunk of shit went from my machine. What a complete waste of time that was.</p>
<p><strong>A good WPF showcase project?</strong></p>
<p>I find it really difficult to actually get my hands on one. <a href="http://msdn.microsoft.com/en-us/netframework/bb499684.aspx" target="_blank">StockTrader</a> is a good candidate for a sample WPF project to look at. However, most of its focus is on service-oriented software design, not so much on WPF. And it shows, as the project is just scratching the surface when it comes to WPF. Otherwise, i can&#8217;t recall any showcase projects with decent UI implementation. I wonder why Microsoft hasn&#8217;t stepped in and released a real-world WPF solution, just like they did Oxite for ASP.NET MVC. The lack of any decent material on WPF and Blend is also pretty astounding for such a hype both caused. All i was able to find was bits and pieces of information, nothing concrete like design patterns, specific design guidelines and such. It just seems like everything&#8217;s up in the air at this point.</p>
<p>I&#8217;m not even sure how to conclude this. I would probably still consider utilizing WPF for new solutions. You still have your standard set of controls and everything to get you started. The unfortunate thing is that you&#8217;ll probably not going to benefit much from the main features of the framework, but you&#8217;ll have to migrate at some point. Might as well do it now and hope that MS enhances their tools a little as the whole thing matures.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Customiser une ListBox en WPF]]></title>
<link>http://wilfriedwoivre.wordpress.com/2009/11/29/customiser-une-listbox-en-wpf/</link>
<pubDate>Sun, 29 Nov 2009 13:48:59 +0000</pubDate>
<dc:creator>Wilfried Woivre</dc:creator>
<guid>http://wilfriedwoivre.wordpress.com/2009/11/29/customiser-une-listbox-en-wpf/</guid>
<description><![CDATA[Il est très courant en WPF que l’on doivent redéfinir le rendu des composants de base afin d’avoir u]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p> Il est très courant en WPF que l’on doivent redéfinir le rendu des composants de base afin d’avoir une interface plus ergonomique pour l’utilisateur. </p>
<p>Prenons par exemple le cas d’une ListBox de personne, qui ressemblerait à peu près à ça :</p>
<p><a href="http://wilfriedwoivre.files.wordpress.com/2009/11/image6.png"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="image" border="0" alt="image" src="http://wilfriedwoivre.files.wordpress.com/2009/11/image_thumb6.png?w=289&#038;h=288" width="289" height="288" /></a></p>
<p>Pour ce code XAML : </p>
<pre class="code"><span style="color:blue;">&#60;</span><span style="color:#a31515;">ListBox </span><span style="color:red;">ItemsSource</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:blue;">}&#34;&#62;
    &#60;</span><span style="color:#a31515;">ListBox.ItemTemplate</span><span style="color:blue;">&#62;
        &#60;</span><span style="color:#a31515;">DataTemplate</span><span style="color:blue;">&#62;
            &#60;</span><span style="color:#a31515;">TextBlock</span><span style="color:blue;">&#62;
                &#60;</span><span style="color:#a31515;">TextBlock.Text</span><span style="color:blue;">&#62;
                    &#60;</span><span style="color:#a31515;">MultiBinding </span><span style="color:red;">StringFormat</span><span style="color:blue;">=&#34;{}{0} {1}&#34;&#62;
                        &#60;</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=&#34;FirstName&#34; /&#62;
                        &#60;</span><span style="color:#a31515;">Binding </span><span style="color:red;">Path</span><span style="color:blue;">=&#34;LastName&#34; /&#62;
                    &#60;/</span><span style="color:#a31515;">MultiBinding</span><span style="color:blue;">&#62;
                &#60;/</span><span style="color:#a31515;">TextBlock.Text</span><span style="color:blue;">&#62;
            &#60;/</span><span style="color:#a31515;">TextBlock</span><span style="color:blue;">&#62;
        &#60;/</span><span style="color:#a31515;">DataTemplate</span><span style="color:blue;">&#62;
    &#60;/</span><span style="color:#a31515;">ListBox.ItemTemplate</span><span style="color:blue;">&#62;
&#60;/</span><span style="color:#a31515;">ListBox</span><span style="color:blue;">&#62;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Maintenant, on va supposer que le client veut que tous les Items soit placé, non pas l’un en dessous de l’autre, mais disperser au niveau de la fenêtre selon différents critères. Il voudrait donc que l’interface ressemble à quelque chose de ce genre : </p>
<p><a href="http://wilfriedwoivre.files.wordpress.com/2009/11/image7.png"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="image" border="0" alt="image" src="http://wilfriedwoivre.files.wordpress.com/2009/11/image_thumb7.png?w=356&#038;h=271" width="356" height="271" /></a></p>
<p>Donc là on voit clairement que selon les besoins des spécifications, les items de la liste ne sont ni vraiment ordonnées, mais plus vraisemblablement placé au hasard dans l’application. Cependant on a tout de même bien affaire à une liste d’élément. </p>
<p>Nous avons donc plusieurs choix qui s’offre à nous, le premier est de créer un Canvas, ou l’on ajoute les éléments 1 à 1 en code behind. Ce choix peut être pas trop mal, mais va de ce fait nécessité un peu de code, et la maintenance sur cet ajout de composant peut rapidement devenir compliqué, surtout si vous voulez “binder” les différents champs.</p>
<p>Notre deuxième choix serait donc de customiser la ListBox, ce qui permettrait uniquement grâce au binding de placer nos Items, sans nous embêter, et de plus nous pourrons rendre ça plus facilement dynamique. Donc, pour cela, on va commencer par faire des tests, on va changer la propriété ItemsPanelTemplate, pour y mettre un Canvas.</p>
<pre class="code">        <span style="color:blue;">&#60;</span><span style="color:#a31515;">ListBox </span><span style="color:red;">ItemsSource</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:blue;">}&#34;&#62;
            &#60;</span><span style="color:#a31515;">ListBox.ItemsPanel</span><span style="color:blue;">&#62;
                &#60;</span><span style="color:#a31515;">ItemsPanelTemplate</span><span style="color:blue;">&#62;
                    &#60;</span><span style="color:#a31515;">Canvas </span><span style="color:blue;">/&#62;
                &#60;/</span><span style="color:#a31515;">ItemsPanelTemplate</span><span style="color:blue;">&#62;
            &#60;/</span><span style="color:#a31515;">ListBox.ItemsPanel</span><span style="color:blue;">&#62;
            &#60;</span><span style="color:#a31515;">ListBox.ItemTemplate</span><span style="color:blue;">&#62;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Puis après, nous allons ajouter deux propriétés à notre objet Personne afin d’y spécifier les coordonnées X et Y de l’item dans la ListBox, notons qu’on pourrait ajouter ces propriétés d’une autre manière, mais là ce n’est qu’une démonstration…. </p>
<p>Ceci fait, nous allons maintenant lier les positions aux propriétés Canvas.Top et Canvas.Left de notre TextBlock. Alors déjà premier petit problème, l’intellisense ne nous fournit pas ces propriétés dans notre DataTemplate, on peut donc se dire que cela provient d’un bug de l’Intellisense, après tout Visual Studio 2008 et le XAML n’apporte pas beaucoup d’aide là ou il le faudrait. Donc on va tout de même le taper et voir si ça compile. </p>
<pre class="code">                <span style="color:blue;">&#60;</span><span style="color:#a31515;">DataTemplate</span><span style="color:blue;">&#62;
                    &#60;</span><span style="color:#a31515;">TextBlock </span><span style="color:red;">Canvas.Top</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Pos</span><span style="color:blue;">.</span><span style="color:red;">Y</span><span style="color:blue;">}&#34; </span><span style="color:red;">Canvas.Left</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Pos</span><span style="color:blue;">.</span><span style="color:red;">X</span><span style="color:blue;">}&#34;&#62;
                        &#60;</span><span style="color:#a31515;">TextBlock.Text</span><span style="color:blue;">&#62;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
</p>
<p>&#160;</p>
<p>Et là c’est magique, Visual Studio compile correctement le projet, ne signale aucune erreur, n’annonce pas de problème de binding dans la sortie. Mais par contre l’application quand à elle ne marche pas comme on le souhaite, car on obtient ceci : </p>
<p><a href="http://wilfriedwoivre.files.wordpress.com/2009/11/image8.png"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="image" border="0" alt="image" src="http://wilfriedwoivre.files.wordpress.com/2009/11/image_thumb8.png?w=329&#038;h=264" width="329" height="264" /></a></p>
<p>On voit ici très bien qu’il ne prend pas en compte nos coordonnées, on se dit maintenant que Visual Studio avait peut être raison de ne pas nous proposer les propriétés Canvas.Left et Canvas.Top sur notre TextBlock.</p>
<p>Après un peu de réflexion, on se dit qu’il faudrait essayer de définir un style à notre Item, et là encore, la ListBox, est bien équipé pour ça, avec sa propriété ItemContainerStyle.</p>
<pre class="code">            <span style="color:blue;">&#60;</span><span style="color:#a31515;">ListBox.ItemContainerStyle</span><span style="color:blue;">&#62;
                &#60;</span><span style="color:#a31515;">Style</span><span style="color:blue;">&#62;
                    &#60;</span><span style="color:#a31515;">Setter </span><span style="color:red;">Property</span><span style="color:blue;">=&#34;Canvas.Left&#34; </span><span style="color:red;">Value</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Pos</span><span style="color:blue;">.</span><span style="color:red;">X</span><span style="color:blue;">}&#34; /&#62;
                    &#60;</span><span style="color:#a31515;">Setter </span><span style="color:red;">Property</span><span style="color:blue;">=&#34;Canvas.Top&#34; </span><span style="color:red;">Value</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding </span><span style="color:red;">Pos</span><span style="color:blue;">.</span><span style="color:red;">Y</span><span style="color:blue;">}&#34; /&#62;
                &#60;/</span><span style="color:#a31515;">Style</span><span style="color:blue;">&#62;
            &#60;/</span><span style="color:#a31515;">ListBox.ItemContainerStyle</span><span style="color:blue;">&#62;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><font face="Lucida Sans Unicode"></font></p>
<p>&#160;</p>
<p>On enlève maintenant nos propriétés de la TextBlock , vu que visiblement elles ne fonctionnent pas, et puis on relance notre application. On obtient donc ainsi notre joli fenêtre : </p>
<p><a href="http://wilfriedwoivre.files.wordpress.com/2009/11/image9.png"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="image" border="0" alt="image" src="http://wilfriedwoivre.files.wordpress.com/2009/11/image_thumb9.png?w=342&#038;h=243" width="342" height="243" /></a></p>
<p>Alors, effectivement comme ça on peut ne pas trop voir l’utilité de repositionner chacun des Items, en fait c’est parce que pour mon projet Imagine Cup, je suis en train de réaliser une ListBox ou les items sont disposés sous forme de cercle. Mais je ne vous dévoile pas tout !</p>
<p>D’ailleurs j’en profite pour passer une annonce, si vous connaissez un étudiant sur Paris qui est intéressé par les technologies comme le XAML, ainsi que l’ergonomie et le design d’application, notre équipe recherche quelqu’un, vous pouvez donc m’envoyer un mail à wilfried.woivre[at]gmail.com.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Alarm Clock Sample -- Part 2]]></title>
<link>http://understandingcsharp.wordpress.com/2009/11/29/alarm-clock-sample-part-2/</link>
<pubDate>Sun, 29 Nov 2009 06:58:07 +0000</pubDate>
<dc:creator>jmancine</dc:creator>
<guid>http://understandingcsharp.wordpress.com/2009/11/29/alarm-clock-sample-part-2/</guid>
<description><![CDATA[Now that I know that myapp.xaml holds the key to the application&#8217;s startup, I want to look clo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Now that I know that <em>myapp.xaml</em> holds the key to the application&#8217;s startup, I want to look closer at where the AppStartup method lives: <em>myapp.xaml.cs</em>.</p>
<p>This file is a complete C# file leveraging the .NET Framework Class Library. The first thing I notice is the file uses six namespaces all ultimately from the System namespace. System is clearly one of the most important namespaces of any C# project. From the descriptions over at the .NET Framework Reference, my first take on their usage is</p>
<ul>
<li>System is required for the most fundamental aspects of the application like class and struct types (eg. the Object class from which all other classes are derived</li>
<li>System.Windows is required because this will be a WPF application</li>
<li>System.Data has no apparent usage at first glance</li>
<li>System.Xml is required to parse XAML files since they are XML files</li>
<li>System.Configuration is required to configure the application (i&#8217;m guessing configuration is detailed in the XAML files)</li>
<li>System.Windows.Media is required for drawing stuff (like the alarm clock image) and producing sound (I don&#8217;t think this alarm clock actually has an alarm though)</li>
</ul>
<p>You don&#8217;t actually have to give everything a namespace but it seems to be a best practice guideline since Microsoft always does it. Here, the application is given the namespace <code>Microsoft.Samples.WinFX.AlarmClock</code>. So far, I don&#8217;t think they are necessary unless you plan to write your own library (compiling as DLLs).</p>
<p>On to the meat: <code>public partial class MyApp : Application</code>.<br />
Of course, the application class should be &#8220;public&#8221; but what&#8217;s with &#8220;partial&#8221;? In <a href="http://understandingcsharp.wordpress.com/2009/11/29/alarm-clock-sample-part-1/">Part 1</a>, I mentioned that the build process will automagically create an entry point method so the application knows how to start, I&#8217;m guessing the build process also creates a class based on <em>myapp.xaml</em> which gets put into separate file from the compiled <em>myapp.xaml.cs</em> in which case &#8220;partial&#8221; is needed to specify this is just part of the class definition. I gathered as much from <a href="http://msdn.microsoft.com/en-us/library/aa970678.aspx">Building a WPF Application</a></p>
<blockquote><p>In addition, a language-specific code file is generated for every XAML file. For example, for a Page1.xaml page in a Visual Basic project, a Page1.g.vb is generated; for a Page1.xaml page in a C# project, a Page1.g.cs is generated. The &#8220;.g&#8221; in the file name indicates the file is generated code that has a partial class declaration for the top-level element of the markup file (such as Page or Window). The class is declared with the partial modifier in C# (Extends in Visual Basic) to indicate there is another declaration for the class elsewhere, usually in the code-behind file Page1.xaml.cs.</p></blockquote>
<p>The main application class is given the name &#8220;MyApp&#8221; and inherits from Application which comes from the System.Windows namespace. The <a href="http://msdn.microsoft.com/en-us/library/system.windows.application.aspx">Application class</a> &#8220;Encapsulates a Windows Presentation Foundation (WPF) application.&#8221; That makes sense, Alarm Clock Sample is a WPF application.</p>
<p>Finally, the application process is run and, on startup, the AppStartup method is called. I already talked about the prototype so let&#8217;s look at the body:</p>
<ul>
<li><code>TraditionalClock tradClock = new TraditionalClock();</code> There&#8217;s an object TraditionalClock defined somewhere (probably in <em>traditionalclock.xaml</em> and <em>traditionalclock.xaml.cs</em>)</li>
<li><code>tradClock.Opacity = .6f;</code> Clearly, this will set the Opacity of the object (which, by now, I&#8217;m assuming consists of at least the image of the clock and hands)</li>
<li><code>tradClock.Show();</code> Most likely renders the clock to the screen.</li>
</ul>
<p>The other method, <code>void clockWindow_Closed(object sender, EventArgs e)</code> is pretty straightforward now that I understand the AppStartup method. It is my understanding that every method triggered by an event will have an &#8220;object sender&#8221; and &#8220;EventArgs e&#8221; argument where EventArgs may be different depending on the event. The body of this method merely contains <code>Application.Current.Shutdown(0);</code> which speaks for itself but the .NET Framework Reference gives some more input: The <a href="http://msdn.microsoft.com/en-us/library/system.windows.application.current.aspx">Current property</a> is thread safe and allows access to the application&#8217;s instance in the current <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.aspx">AppDomain</a> (kind of like a sandbox for each executing application) from any thread. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Alarm Clock Sample -- Part 1]]></title>
<link>http://understandingcsharp.wordpress.com/2009/11/29/alarm-clock-sample-part-1/</link>
<pubDate>Sun, 29 Nov 2009 03:18:27 +0000</pubDate>
<dc:creator>jmancine</dc:creator>
<guid>http://understandingcsharp.wordpress.com/2009/11/29/alarm-clock-sample-part-1/</guid>
<description><![CDATA[The Calculator Demo I visited previously is far too complex for now so I&#8217;ve decided to try to ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The Calculator Demo I visited <a href="http://understandingcsharp.wordpress.com/2009/11/28/calculator-demo-part-1/">previously</a> is far too complex for now so I&#8217;ve decided to try to understand the <a href="http://msdn.microsoft.com/en-us/library/ms756487.aspx">Alarm Clock Sample</a> instead. It is a much simpler application though still written for WPF and as such is using XAML.</p>
<p>Upon downloading the source, I first built the project. This time, there were no problems. The build succeeded and I opened the app. Just as I suspected, it was very simple&#8211;just a picture of an old school alarm clock with animated hands, opacity set as to not be opaque, and draggable whilst showing the outline of an outrageously large rectangle. I was surprised, however, that it was taking 50% of my processing power which, on a dual core processor, means it&#8217;s maxing out probably because of some infinite loop.</p>
<p>Ok, so now that I see what the program is all about, it&#8217;s time to dive into the code. I went straight for <em>myapp.xaml</em> to find <code>Startup</code>. Thanks to the <a href="http://msdn.microsoft.com/en-us/library/ms743714.aspx">WPF Application Management Overview</a>, I know now that this is used to define the handler for the Application.Startup Event which &#8220;<a href="http://msdn.microsoft.com/en-us/library/system.windows.application.startup.aspx">Occurs when the Run method of the Application object is called.</a>&#8220;</p>
<p>I now understand the syntax of <code>void AppStartup(object sender, StartupEventArgs e)</code> in <em>app.xaml.cs</em>.</p>
<ul>
<li><strong>void</strong> means this method will not return anything (basic knowledge from any strongly typed programming language)</li>
<li><strong>AppStartup</strong> defines the name of the method which will be called on activation of the Application.Startup Event.</li>
<li><strong>object sender</strong> is a reference to the object which raised the event</li>
<li><strong>StartupEventArgs e</strong> gives access to the properties of the event in question</li>
</ul>
<p>Cool, but the Startup event &#8220;Occurs when the Run method of the Application object is called.&#8221; Doesn&#8217;t that mean the application needs a &#8220;Run method&#8221;? Usually the Run method gets put into the Main method but it doesn&#8217;t exist in the Alarm Clock Sample just as it didn&#8217;t exist in the Calculator Demo. No such luck finding Run either. The answer lies in the background. What we don&#8217;t see in the application nor during the build process is that the entry point Main and the all-important Run get inserted automagically. I felt lucky searching for &#8220;wpf main()&#8221; and I was. Someone asked <a href="http://learnwpf.com/Posts/Post.aspx?postId=a5643949-ab80-47f9-93c8-f5e8e5782d34">How can I provide my own Main() method in my WPF application?</a> (I&#8217;ll have to look further into that website sometime) and the answer was </p>
<blockquote><p>At compile-time WPF generates the real entry point method using the classic static void Main() method signature in C#, or Public Shared Sub Main() in VB.NET. Inside the Main() method WPF creates an instance of one of your classes which derive from System.Windows.Application, and calls the blocking Run() method on this Application-derived class which keeps the process &#8220;alive&#8221;.</p></blockquote>
<p>Perfect. Now, I can figure out how the app is actually put together rather than how it can exist in the first place.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Fishbowl — opensource клиент от Microsoft]]></title>
<link>http://knoxknox.wordpress.com/2009/11/28/fishbowl-%e2%80%94-opensource-%d0%ba%d0%bb%d0%b8%d0%b5%d0%bd%d1%82-%d0%be%d1%82-microsoft/</link>
<pubDate>Sat, 28 Nov 2009 19:50:56 +0000</pubDate>
<dc:creator>knox</dc:creator>
<guid>http://knoxknox.wordpress.com/2009/11/28/fishbowl-%e2%80%94-opensource-%d0%ba%d0%bb%d0%b8%d0%b5%d0%bd%d1%82-%d0%be%d1%82-microsoft/</guid>
<description><![CDATA[Microsoft выпустила Fishbowl — opensource клиент для Facebook с богатым функционалом. Fishbowl предс]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Microsoft выпустила Fishbowl — opensource клиент для Facebook с богатым функционалом. Fishbowl представлется собой клиентское приложение, которое дает удобный и быстрый доступ ко всем функциям Facebook.</p>
<p style="text-align:left;"><img class="aligncenter" title="fbfw" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/FishbowlforFacebookPreview.png" alt="" width="450" /> Приложение Fishbowl может работать в двух режимах: стандартном и минимизированном. Во втором случае на экране появляется небольшое окошко с последними обновлениями статусов ваших друзей.</p>
<p style="text-align:left;">В наличии тесная интеграция с Windows 7 Aero: отображение обновлений, быстрый доступ к функциям через JumpLists, Aero Preview.</p>
<p style="text-align:center;"><img class="alignnone" title="status" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/41.jpg" alt="" width="238" height="223" /><img class="alignnone" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/31.jpg" alt="" width="206" height="262" /></p>
<p style="text-align:center;"><img class="aligncenter" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/dragndrop.png" alt="" width="558" height="323" /></p>
<p>Просмотр загруженных фотографий удобен:</p>
<p style="text-align:center;"><img class="aligncenter" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/FishbowlforFacebookPreview2.png" alt="" width="519" height="412" /></p>
<p style="text-align:center;"><img class="aligncenter" src="http://www.ithinkdiff.com/wp-content/uploads/2009/11/FishbowlforFacebookPreview3.png" alt="" width="523" height="415" /></p>
<p>Кроме того, Fishbowl поддерживает проверку орфографии, пока только на английском языке.</p>
<p>via <a href="www.ithinkdiff.com/fishbowl-desktop-facebook-client-optimized-for-windows-7/">www.ithinkdiff.com/fishbowl-desktop-facebook-client-optimized-for-windows-7/</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Calculator Demo -- Part 1]]></title>
<link>http://understandingcsharp.wordpress.com/2009/11/28/calculator-demo-part-1/</link>
<pubDate>Sat, 28 Nov 2009 13:52:09 +0000</pubDate>
<dc:creator>jmancine</dc:creator>
<guid>http://understandingcsharp.wordpress.com/2009/11/28/calculator-demo-part-1/</guid>
<description><![CDATA[After reading through a bunch of the .Net Framework Class Library, I noticed they have some samples ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>After reading through a bunch of the .Net Framework Class Library, I noticed they have some samples for download. I really wanted to dive into GUI programming so I checked out the <a href="http://msdn.microsoft.com/en-us/library/ms771362.aspx">Calculator Demo</a>.</p>
<p>I knew it would be fairly complicated from the description but when I opened the source, I was taken aback by the complexity. As the comments pointed out, it wouldn&#8217;t compile correctly in the command line because of &#8220;missing files&#8221; but I still couldn&#8217;t get that to work so I fired up the behemoth Visual Studio and, it&#8217;s true, &#8220;this example doesn&#8217;t build unless&#8230;&#8221;.</p>
<p>The calculator was running, I played around to experience the features, then went back to the source code. From the tutorials I had looked at <a href="http://understandingcsharp.wordpress.com/2009/11/28/initial-resources/">previously</a>, I knew every C# program needed to have a static Main() method as a starting point. I searched every file for &#8220;Main&#8221; but to no avail. I searched the internet for C# applications without Main() but to no avail. </p>
<p>Since the easy path to understanding wasn&#8217;t working out, I stretched my arms and began looking through each source file for the starting point of the application. Eventually, I found <code>Startup="AppStartingUp"</code> in <em>app.xaml</em> which quickly led me to <code>void AppStartingUp(object sender, StartupEventArgs e)</code> in <em>app.xaml.cs</em> (conveniently enough).</p>
<p>This discovery didn&#8217;t help me understand what was happening but it did lead me to search for <a href="http://msdn.microsoft.com/en-us/library/ms747122.aspx">xaml</a> which happens to stand for &#8220;Extensible Application Markup Language&#8221; and, like C# and .NET, was created by Microsoft and looks to be just as complicated.</p>
<p>Of course, since I had never heard of it before, I realized I would need to find a primer on XAML. <a href="http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=143">My First XAML Application</a> is a perfect introduction. As it turns out, the C# language isn&#8217;t too difficult but .NET is a tremendously large framework which is going to force me to learn a lot more than just C#. I mean, XAML is just part of the <a href="http://msdn.microsoft.com/en-us/library/ms754130.aspx">Windows Presentation Foundation</a>!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Use Visual Brush to fill the shape with Controls]]></title>
<link>http://zamjad.wordpress.com/2009/11/26/use-visual-brush-to-fill-the-shape-with-controls/</link>
<pubDate>Fri, 27 Nov 2009 04:54:40 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/26/use-visual-brush-to-fill-the-shape-with-controls/</guid>
<description><![CDATA[We have already discuss the usage of Visual Brush and see how we can use it to make a text reflectio]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We have already discuss the usage of Visual Brush and see how we can use it to make a text reflection. This time we are going to make a visual brush to fill the geometrical shape with control. We will do a binding of Visual Brush with UIElement, just like we use to do data binding with other UIElement. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Ellipse</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: 	<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Ellipse.Fill</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: 		<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">VisualBrush</span> <span style="color:#ff0000;">Visual</span>=<span style="color:#0000ff;">&#34;{Binding ElementName=list}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: 	<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Ellipse.Fill</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Ellipse</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: </pre>
</pre>
<p> Here is a class diagram of Brush class. </p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/brush.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="Brush" border="0" alt="Brush" src="http://zamjad.files.wordpress.com/2009/11/brush_thumb.gif?w=652&#038;h=323" width="652" height="323" /></a></p>
<p>Here is a complete program to fill the ellipse with a lix box usingVisual Brush.&#160; </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;VisualBrush.Window1&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:     <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:     <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:     <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;Visual Brush&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;400&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;400&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;list&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Background</span>=<span style="color:#0000ff;">&#34;AliceBlue&#34;</span> <span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListBox.ItemTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13:                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">FontSize</span>=<span style="color:#0000ff;">&#34;14&#34;</span> <span style="color:#ff0000;">Foreground</span>=<span style="color:#0000ff;">&#34;Navy&#34;</span> <span style="color:#ff0000;">Text</span>=<span style="color:#0000ff;">&#34;{Binding}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:                 <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListBox.ItemTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Ellipse</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Ellipse.Fill</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">VisualBrush</span> <span style="color:#ff0000;">Visual</span>=<span style="color:#0000ff;">&#34;{Binding ElementName=list}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Ellipse.Fill</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Ellipse</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25: </pre>
</pre>
<p>Here is C# code of this program.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">using</span> System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">using</span> System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">using</span> System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">using</span> System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">using</span> System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">using</span> System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">using</span> System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">using</span> System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">using</span> System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">using</span> System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: <span style="color:#0000ff;">using</span> System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: <span style="color:#0000ff;">using</span> System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">using</span> System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: <span style="color:#0000ff;">namespace</span> VisualBrush
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:     <span style="color:#808080;">/// &#60;summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:     <span style="color:#808080;">/// Interaction logic for Window1.xaml</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     <span style="color:#808080;">/// &#60;/summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     <span style="color:#0000ff;">public</span> partial <span style="color:#0000ff;">class</span> Window1 : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">public</span> Window1()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:             List&#60;String&#62; stateList = <span style="color:#0000ff;">new</span> List&#60;<span style="color:#0000ff;">string</span>&#62;();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:             stateList.Add(&#34;<span style="color:#8b0000;">Maryland</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:             stateList.Add(&#34;<span style="color:#8b0000;">California</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:             stateList.Add(&#34;<span style="color:#8b0000;">Virginia</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:             stateList.Add(&#34;<span style="color:#8b0000;">Washington</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:             stateList.Add(&#34;<span style="color:#8b0000;">New York</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:             stateList.Add(&#34;<span style="color:#8b0000;">Nevada</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:             stateList.Add(&#34;<span style="color:#8b0000;">Florida</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:             stateList.Add(&#34;<span style="color:#8b0000;">Arizona</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:             list.ItemsSource = stateList;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41: </pre>
</pre>
<p>This is the output of this program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/visualbrushoutput.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="VisualBrushOutput" border="0" alt="VisualBrushOutput" src="http://zamjad.files.wordpress.com/2009/11/visualbrushoutput_thumb.gif?w=400&#038;h=400" width="400" height="400" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Workshop: WPF &amp; WCF]]></title>
<link>http://arkcore.wordpress.com/2009/11/26/workshop-wpf-wcf-2/</link>
<pubDate>Thu, 26 Nov 2009 20:20:41 +0000</pubDate>
<dc:creator>Danijel Malik</dc:creator>
<guid>http://arkcore.wordpress.com/2009/11/26/workshop-wpf-wcf-2/</guid>
<description><![CDATA[After a few busy weeks (Mondays and Thursdays) our workshop has reached the end. I hope that guys wh]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>After a few busy weeks (Mondays and Thursdays) our workshop has reached the end. I hope that guys who had attended this workshop had some joy and got some knowledge/experience with these technologies <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I’d be glad to repeat it, but there are some other interesting areas to cover, so keep reading my blog to find out when’s the next workshop.</p>
<p>Best wishes!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[enabling Async methods for wcf in wpf]]></title>
<link>http://dotnettrails.wordpress.com/2009/11/26/enabling-async-methods-for-wcf-in-wpf/</link>
<pubDate>Thu, 26 Nov 2009 09:08:14 +0000</pubDate>
<dc:creator>dotnettrails</dc:creator>
<guid>http://dotnettrails.wordpress.com/2009/11/26/enabling-async-methods-for-wcf-in-wpf/</guid>
<description><![CDATA[By default when you add a WCF Service reference in WPF, it does not give async functions. If your ap]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>By default when you add a WCF Service reference in WPF, it does not give async functions. If your application needs async features, while adding a reference to the service, lookout for a ‘Advanced’ button on Add service reference window at bottom right corner. On clicking on that button, a new window appears. There is a checkbox called ‘Generate Asynchronous Operations’. Hit Ok and you are done!</p>
<p>Simple isn’t it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ba4182f1-2519-4893-a5e2-5d663dcc669b" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/WCF" rel="tag">WCF</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/Enable+Async+Methods" rel="tag">Enable Async Methods</a>,<a href="http://technorati.com/tags/Tweak" rel="tag">Tweak</a>,<a href="http://technorati.com/tags/Configuration" rel="tag">Configuration</a>,<a href="http://technorati.com/tags/Simple+settings" rel="tag">Simple settings</a></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WPF Programming in MSIL]]></title>
<link>http://zamjad.wordpress.com/2009/11/25/wpf-programming-in-msil/</link>
<pubDate>Thu, 26 Nov 2009 04:58:49 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/25/wpf-programming-in-msil/</guid>
<description><![CDATA[Today i got some free time and decided to play with MSIL and did little experiment with it. I did on]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Today i got some free time and decided to play with MSIL and did little experiment with it. I did one small experiment and try to make one simple application of WPF in MSIL. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: .<span style="color:#0000ff;">assembly</span> Wpfil{}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: .<span style="color:#0000ff;">method</span> <span style="color:#0000ff;">static</span> void start ()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     .entrypoint
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:     .maxstack 8
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: 	<span style="color:#0000ff;">ldstr</span> &#34;<span style="color:#8b0000;">Hello World from MSIL</span>&#34;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	<span style="color:#0000ff;">call</span> valuetype [PresentationFramework]System.Windows.MessageBoxResult [PresentationFramework]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: System.Windows.MessageBox::Show(<span style="color:#0000ff;">class</span> System.String)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: 	<span style="color:#0000ff;">pop</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 	<span style="color:#0000ff;">ret</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14: </pre>
</pre>
<p>The output of this program is one message box with “Hello World from MSIL”. But this message box is from WPF not a windows standard message box. </p>
<p>But if we want to display a window in WPF then we have to create object of at least two class Application and Window class. Here is a MSIL code to create object of Window and Application class.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Window::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: stloc.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Application::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: stloc.1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: </pre>
</pre>
<p>But first we have to set the attribute of program as a single threaded. We can do it with the following MSIL statement. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: .<span style="color:#0000ff;">custom</span> <span style="color:#0000ff;">instance</span> void [mscorlib]System.STAThreadAttribute::.ctor()</pre>
</pre>
<p>Here is a complete MSIL code of the program.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: .<span style="color:#0000ff;">assembly</span> Wpfil{}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: .<span style="color:#0000ff;">method</span> <span style="color:#0000ff;">static</span> void start ()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     .entrypoint
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: 	.<span style="color:#0000ff;">custom</span> <span style="color:#0000ff;">instance</span> void [mscorlib]System.STAThreadAttribute::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:     .maxstack 8
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	.locals <span style="color:#0000ff;">init</span> ([0] <span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Window win,
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: 		[1] <span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Application app)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 	<span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Window::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	stloc.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: 	<span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Application::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: 	stloc.1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19: 	<span style="color:#0000ff;">ldstr</span> &#34;<span style="color:#8b0000;">Hello World from MSIL</span>&#34;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Window::set_Title(string)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22: 	<span style="color:#0000ff;">ldloc</span>.1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> <span style="color:#0000ff;">int</span>32 [PresentationFramework]System.Windows.Application::Run(<span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Window)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25: 	<span style="color:#0000ff;">pop</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26: 	<span style="color:#0000ff;">ret</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28: </pre>
</pre>
<p>The output of this program is one window with “Hello World from MSIL” caption. </p>
<p>Similarly we can define other properties of the window. Here is an example toe set the width and height of the window. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: .<span style="color:#0000ff;">assembly</span> Wpfil{}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: .<span style="color:#0000ff;">method</span> <span style="color:#0000ff;">static</span> void start ()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     .entrypoint
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: 	.<span style="color:#0000ff;">custom</span> <span style="color:#0000ff;">instance</span> void [mscorlib]System.STAThreadAttribute::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:     .maxstack 8
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	.locals <span style="color:#0000ff;">init</span> ([0] <span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Window win,
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: 		[1] <span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Application app)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 	<span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Window::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	stloc.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: 	<span style="color:#0000ff;">newobj</span>     <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Application::.ctor()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: 	stloc.1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19: 	ldc.r8     400
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.FrameworkElement::set_Width(<span style="color:#0000ff;">float</span>64)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23: 	ldc.r8     300
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.FrameworkElement::set_Height(<span style="color:#0000ff;">float</span>64)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27: 	<span style="color:#0000ff;">ldstr</span> &#34;<span style="color:#8b0000;">Hello World from MSIL</span>&#34;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> void [PresentationFramework]System.Windows.Window::set_Title(string)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30: 	<span style="color:#0000ff;">ldloc</span>.1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31: 	<span style="color:#0000ff;">ldloc</span>.0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32: 	<span style="color:#0000ff;">callvirt</span>   <span style="color:#0000ff;">instance</span> <span style="color:#0000ff;">int</span>32 [PresentationFramework]System.Windows.Application::Run(<span style="color:#0000ff;">class</span> [PresentationFramework]System.Windows.Window)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33: 	<span style="color:#0000ff;">pop</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34: 	<span style="color:#0000ff;">ret</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36: </pre>
</pre>
<p>Here is the output of this program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/msilwpf.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="MSILWPF" border="0" alt="MSILWPF" src="http://zamjad.files.wordpress.com/2009/11/msilwpf_thumb.gif?w=400&#038;h=300" width="400" height="300" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Silverlight and WPF Single-Sourcing &ndash; XAML namespaces]]></title>
<link>http://blog.elgaard.com/2009/11/25/silverlight-and-wpf-single-sourcing-%e2%80%93-xaml-namespaces/</link>
<pubDate>Wed, 25 Nov 2009 21:06:19 +0000</pubDate>
<dc:creator>belgaard</dc:creator>
<guid>http://blog.elgaard.com/2009/11/25/silverlight-and-wpf-single-sourcing-%e2%80%93-xaml-namespaces/</guid>
<description><![CDATA[I have found that WPF and Silverlight XAML are sufficiently different to make single-sourcing diffic]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have found that WPF and Silverlight XAML are sufficiently different to make single-sourcing difficult.</p>
<p>At first I did not know if it was possible at all, but I knew one thing – the differences in usage of namespaces look like something very annoying for which there must be an elegant solution.</p>
<h4>The Problem   <br /></h4>
<p>The first issue was with the standard controls which are in WPF 4.0 but <em>not</em> in Silverlight 3.0 (only in the <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=Silverlight">toolkit</a>), e.g. the Expander is declared like this in WPF,</p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:blue;">&#60;</span><span style="color:#a31515;">Expander</span><span style="color:red;"> … /</span><span style="color:blue;">&#62;</span></span></p>
<p>But it is declared like this in Silverlight,</p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:red;">… xmlns</span><span style="color:blue;">:</span><span style="color:red;">Controls1</span><span style="color:blue;">=&#34;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit&#34; …       <br />&#60;</span><span style="color:#a31515;">Controls1</span><span style="color:blue;">:</span><span style="color:#a31515;">Expander</span><span style="color:red;"> … /</span><span style="color:blue;">&#62;       <br /></span></span></p>
<p>What I really did not understand was that there is a similar problem when the standard controls which are in WPF 4.0 <em>also are</em> in Silverlight 3.0; for example, the <span style="font-family:courier new;color:#a31515;font-size:10pt;">HierarchicalDataTemplate</span> is declared like this in WPF,</p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:blue;">&#60;</span><span style="color:#a31515;">HierarchicalDataTemplate … /&#62;</span></span></p>
<p>But it is declared like this in Silverlight,</p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:red;">… xmlns</span><span style="color:blue;">:</span><span style="color:red;">Windows</span><span style="color:blue;">=&#34;clr-namespace:System.Windows;assembly=System.Windows.Controls&#34; …       <br />&#60;</span><span style="color:#a31515;">Windows</span><span style="color:blue;">:</span><span style="color:#a31515;">HierarchicalDataTemplate … /&#62;       <br /></span></span></p>
<p>Clearly the rules for defaulting and declaring namespaces are different.</p>
<h4>The First Solution   <br /></h4>
<p>I searched the Internet and found a few suggestions. One suggestion is to have two sets of name space references. This works because you are allowed to use name spaces on WPF although it is not mandatory. I did not like it because it still meant maintaining different files since XAML does not allow #IFDEF-like constructs.</p>
<p>My colleague David Anson found a surprisingly simple solution which he describes in a <a href="http://blogs.msdn.com/delay/archive/2009/10/21/two-birds-one-stone-silverlight-wpf-data-visualization-development-release-2-and-datavisualizationdemos-update.aspx">blog</a> post (see the last bullet in the notes at the end of the post). The main idea is to subclass standard controls, effectively bringing them into the same namespace across Silverlight and WPF.</p>
<p>It looks like magic – and <a href="http://www.jetbrains.com/resharper/">ReSharper</a> also claims that this is not valid – but it works. Well, it almost works.</p>
<h4>The Problem with the First Solution   <br /></h4>
<p>So far I have found one problem with the first solution – the <span style="font-family:courier new;color:#a31515;font-size:10pt;">HierarchicalDataTemplate</span><span style="color:#1f497d;">.     <br /></span></p>
<p>If I used David&#8217;s trick,</p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:blue;">public </span><span style="color:blue;">class </span><span style="color:#2b91af;">HierarchicalDataTemplate</span> : System.Windows.<span style="color:#2b91af;">HierarchicalDataTemplate</span> { }      <br /></span></p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:red;">Std</span><span style="color:blue;">=&#34;clr-namespace:Microsoft.Dynamics.Ax.Frameworks.Controls.StandardControls&#34;</span></span><span style="color:#1f497d;">     <br /></span></p>
<p><span style="font-family:courier new;font-size:10pt;"><span style="color:blue;">41: &#60;</span><span style="color:#a31515;">Std</span><span style="color:blue;">:</span><span style="color:#a31515;">HierarchicalDataTemplate</span><span style="color:red;"> x</span><span style="color:blue;">:</span><span style="color:red;">Key</span><span style="color:blue;">=&#34;hierarchicalDataTemplate&#34;</span><span style="color:red;"> ItemsSource</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:red;"> Path</span><span style="color:blue;">=Subcomponents}&#34;&#62;       <br /></span><span style="color:#a31515;">42:&#160;&#160;&#160; </span><span style="color:blue;">&#60;</span><span style="color:#a31515;">StackPanel</span><span style="color:red;"> Orientation</span><span style="color:blue;">=&#34;Horizontal&#34;&#62;       <br />43:&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;</span><span style="color:#a31515;">Image</span><span style="color:red;"> Source</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:red;"> Path</span><span style="color:blue;">=TreeIcon}&#34;/&#62;       <br /></span><span style="color:#a31515;">44:&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color:blue;">&#60;</span><span style="color:#a31515;">TextBlock</span><span style="color:red;"> Text</span><span style="color:blue;">=&#34;{</span><span style="color:#a31515;">Binding</span><span style="color:red;"> Path</span><span style="color:blue;">=Name}&#34;/&#62;       <br /></span><span style="color:#a31515;">45:&#160;&#160;&#160; </span><span style="color:blue;">&#60;/</span><span style="color:#a31515;">StackPanel</span><span style="color:blue;">&#62;       <br />46: &#60;/</span><span style="color:#a31515;">Std</span><span style="color:blue;">:</span><span style="color:#a31515;">HierarchicalDataTemplate</span><span style="color:blue;">&#62;       <br /></span></span></p>
<p>Then it compiled in Silverlight and WPF but the <span style="font-family:courier new;color:#a31515;font-size:10pt;">StackPanel</span> caused problems at run-time in WPF. The error was</p>
<blockquote><p>&#8216;StackPanel&#8217; object cannot be added to &#8216;HierarchicalDataTemplate&#8217;. Object of type &#8216;System.Windows.Controls.StackPanel&#8217; cannot be converted to type &#8216;System.Windows.FrameworkElementFactory&#8217;.&#160; Error at object &#8216;System.Windows.Controls.StackPanel&#8217; in markup file &#8216;Microsoft.Dynamics.Ax.Frameworks.Controls;component/singlesourcetest.xaml&#8217; Line 42 Position 26.</p>
</blockquote>
<p>It did not help to use David&#8217;s trick again and add <span style="font-family:courier new;color:#a31515;font-size:10pt;">StackPanel</span> to the <span style="font-family:courier new;color:#a31515;font-size:10pt;">Std</span> namespace.</p>
<p>This is a WPF bug. It has not been fixed in the WPF 4.0 beta I am using but I hope it will be fixed eventually in the RTM.</p>
<h4>The Second Solution   <br /></h4>
<p>David worked hard on this problem and got another brilliant idea; if this is a problem with WPF only then why not subclass in Silverlight only? This requires a little trick that left David &#34;a little slimy&#34; – see his <a href="http://blogs.msdn.com/delay/archive/2009/11/23/sharing-isn-t-easy-for-anyone-tricks-for-sharing-the-same-xaml-files-across-silverlight-and-wpf.aspx">blog post</a> for the details – but it works. Well, it almost works.</p>
<h4>The Problem with the Second Solution   <br /></h4>
<p>I took the sample project from the <a href="http://blogs.msdn.com/delay/archive/2009/11/23/sharing-isn-t-easy-for-anyone-tricks-for-sharing-the-same-xaml-files-across-silverlight-and-wpf.aspx">blog post</a> for a spin and found that it would not work if I added <span style="font-family:courier new;font-size:10pt;"><span style="color:red;">x</span><span style="color:blue;">:</span><span style="color:red;">Name</span><span style="color:blue;">=&#34;myTreeview</span></span>&#34; to the TreeView in XAML. This is the error I got,</p>
<blockquote><p>The type &#8216;System.Windows.Controls.TreeView&#8217; exists in both &#8216;c:\Program Files\Microsoft SDKs\Silverlight\v3.0\Libraries\Client\System.Windows.Controls.dll&#8217; and &#8216;e: \SharingXamlSilverlightWpf\PresentationFramework\Bin\Debug\PresentationFramework.dll&#8217;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e:\enlistments\axmain6\source\frameworks\controls\sharingxamlsilverlightwpf\sharingxamlsilverlightwpf-sl\obj\debug\mainpage.g.cs&#160;&#160;&#160;&#160;&#160; 38&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 42&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SharingXamlSilverlightWpf-SL</p>
</blockquote>
<p>Clearly there is a problem with disambiguating identical names across assemblies.</p>
<p>I needed to reference the name of the tree from a details view so I could not use the second solution for at least the controls that I needed to name.</p>
<p>But since the second solution seemed to only be needed for <span style="font-family:courier new;color:#a31515;font-size:10pt;">HierarchicalDataTemplate</span> anyway, I am now using the first solution for everything but the <span style="font-family:courier new;color:#a31515;font-size:10pt;">HierarchicalDataTemplate</span>.</p>
<p>And this works. Well, it almost works. But the remaining problems seem to be unrelated to this single-sourcing approach so I will defer blogging about it till later.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Tips, Tutorial y Truco: Boton con Efecto de Vidrio (Button Glass) en SilverLight]]></title>
<link>http://alexjimenez.wordpress.com/2009/11/25/tips-tutorial-y-truco-boton-con-efecto-de-vidrio-button-glass-en-silverlight/</link>
<pubDate>Wed, 25 Nov 2009 15:54:00 +0000</pubDate>
<dc:creator>Alex Jiménez</dc:creator>
<guid>http://alexjimenez.wordpress.com/2009/11/25/tips-tutorial-y-truco-boton-con-efecto-de-vidrio-button-glass-en-silverlight/</guid>
<description><![CDATA[Hola a todos, Me gustar&iacute;a compartir este peque&ntilde;o tutorial de como obtener un bot]]></description>
<content:encoded><![CDATA[Hola a todos, Me gustar&iacute;a compartir este peque&ntilde;o tutorial de como obtener un bot]]></content:encoded>
</item>
<item>
<title><![CDATA[WPF: Replicating MDI Application Behaviour]]></title>
<link>http://waxtadpole.wordpress.com/2009/11/25/wpf-replicating-mdi-application-behaviour/</link>
<pubDate>Wed, 25 Nov 2009 06:36:58 +0000</pubDate>
<dc:creator>baraholka1</dc:creator>
<guid>http://waxtadpole.wordpress.com/2009/11/25/wpf-replicating-mdi-application-behaviour/</guid>
<description><![CDATA[I decided to use Prism, aka Microsoft Composite Application Guidance For WPF and Silverlight. This i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I decided to use <strong>Prism,</strong> aka Microsoft<a href="http://msdn.microsoft.com/en-us/library/dd458809.aspx"> Composite Application Guidance For WPF and Silverlight.</a></p>
<p>This is very much like using a supersonic jet fighter to pop down to the local shops but its effective, not very hard and does not require you to write reams of fragile custom code. You just need to spend a bit of time getting used to Prism. Now that&#8217;s not a <em>trivial </em>task, but you should have covered the fundamental concepts within a working week, assuming you have some prior knowledge of Dependency Injection.</p>
<p>The huge advantage to you is that Prism is written by people who are much better programmers than you or I are, so the code is robust, whereas writing a custom MDI Window Manager is out of the league of most Intermediate-level developers (most of us).</p>
<p>Very simply, Prism allows the development of <i>Modular Applications </i> in which the User Interface of an application is decomposed into loosely-coupled <em>Modules</em>, each of which occupies a specific area on the screen, known as a <em>Region.</em></p>
<p>No window (known in Prism as a <em>View</em>) can move outside the <em>Region</em> in which it is contained. This replicates the MDI-like behaviour you&#8217;re looking for.</p>
<p>Prism is also a library of <em>Best Practices</em> &#8211; it&#8217;s produced by the <a href="http://msdn.microsoft.com/en-us/default.aspx">Microsoft Patterns and Practices</a> team &#8211; so you get heaps of built-ins for free. And <a href="http://www.codeplex.com/CompositeWPF/Thread/List.aspx">there&#8217;s a helpful forum </a>where others using Prism are happy to help us newbies.</p>
<p>You can also have multiple windows (views) open simultaneously if you want, but this will render as a tabbed interface which is not exactly the same as MDI.</p>
<p>I embarked upon this approach and have been successful in producing a MDI-like app. It wasn&#8217;t too hard and I learnt heaps along the way. Go for it.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[custom setting tab order in wpf application]]></title>
<link>http://dotnettrails.wordpress.com/2009/11/25/custom-setting-tab-order-in-wpf-application/</link>
<pubDate>Wed, 25 Nov 2009 06:05:16 +0000</pubDate>
<dc:creator>dotnettrails</dc:creator>
<guid>http://dotnettrails.wordpress.com/2009/11/25/custom-setting-tab-order-in-wpf-application/</guid>
<description><![CDATA[For the framework element set KeyboardNavigation.TabIndex=&quot;&lt;number goes here&gt;&quot; Simpl]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>For the framework element set KeyboardNavigation.TabIndex=&#34;&#60;number goes here&#62;&#34;</p>
<p>Simple isn’t it?</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d2fc1d26-f573-4181-ac07-787e83f5058c" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/tab+order" rel="tag">tab order</a>,<a href="http://technorati.com/tags/Keyboard+navigation" rel="tag">Keyboard navigation</a>,<a href="http://technorati.com/tags/tabindex" rel="tag">tabindex</a></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Data Triggers and Usage in XAML]]></title>
<link>http://codingsense.wordpress.com/2009/11/25/data-triggers-and-usage-in-xaml/</link>
<pubDate>Wed, 25 Nov 2009 05:40:42 +0000</pubDate>
<dc:creator>codingsense</dc:creator>
<guid>http://codingsense.wordpress.com/2009/11/25/data-triggers-and-usage-in-xaml/</guid>
<description><![CDATA[Hi, DataTrigger represents a trigger that applies property values or performs actions when the bound]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><font face="Verdana,Arial,Helvetica,sans-serif" size="2">Hi,</p>
<p>DataTrigger represents a trigger that applies property values or performs actions when the bound data meets a specified condition.</p>
<p>In this sample we will explore how this property can be utilized on how we need it to behave. In this sample I will concentrate on Style Triggers and apply them on the datagrid, in similar fashion it can be applied to any of the container control.</p>
<p>Till now I have been using Data Triggers in many of the places in my project. Combining all the solutions I have made a sample in which i will be describing all the types of usages of Data Triggers. </p>
<p>Let us imagine a collection of Fathers which hold FirstName of fathers. Each father has a kids collection where all his kids names are stored.<br />
The collection are displayed in a datagrid and the rows are displayed using a Listview and a gridview.</font></p>
<pre style="overflow:auto;width:95%;color:#000000;line-height:14px;border:#999999 1px dashed;font-size:15px;padding:5px;">
<font color="#0000FF" size="2">&#60;</font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid</font><font color="#FF0000" size="2"> AutoGenerateColumns</font><font color="#0000FF" size="2">="False"</font><font color="#FF0000" size="2"> Margin</font><font color="#0000FF" size="2">="28,39,33,21"</font><font color="#FF0000" size="2"> Name</font><font color="#0000FF" size="2">="dataGrid1"&#62;············
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid.RowDetailsTemplate</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">DataTemplate</font><font color="#0000FF" size="2">&#62;····················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">ListView</font><font color="#FF0000" size="2"> Name</font><font color="#0000FF" size="2">="Kids"</font><font color="#FF0000" size="2"> ItemsSource</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> Kids</font><font color="#0000FF" size="2">}"&#62;························
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">ListView.View</font><font color="#0000FF" size="2">&#62;····························
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">GridView</font><font color="#0000FF" size="2">&#62;································
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">GridViewColumn </font><font color="#FF0000" size="2"> Header</font><font color="#0000FF" size="2">="Kids"</font><font color="#FF0000" size="2"> DisplayMemberBinding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> Name</font><font color="#0000FF" size="2">}"/&#62;····························
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">GridView</font><font color="#0000FF" size="2">&#62;························
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">ListView.View</font><font color="#0000FF" size="2">&#62;····················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">ListView</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">DataTemplate</font><font color="#0000FF" size="2">&#62;············
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid.RowDetailsTemplate</font><font color="#0000FF" size="2">&#62;············
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid.Columns</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGridTextColumn</font><font color="#FF0000" size="2"> Header</font><font color="#0000FF" size="2">="Father Name"</font><font color="#FF0000" size="2"> Binding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> FirstName</font><font color="#0000FF" size="2">}"/&#62;············
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid.Columns</font><font color="#0000FF" size="2">&#62;········
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">my</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">DataGrid</font><font color="#0000FF" size="2">&#62;</font>
</pre>
<p><font face="Verdana,Arial,Helvetica,sans-serif" color="#000000" size="2">Now lets create some scenarios in our project in the format the details are to be displayed<br />
<b>Scenario1:</b> Make the families background red where there are no kids<br />
<b>Scenario 2:</b> Hide the families where the name of the father is less than 8 chars<br />
<b>Scenario 3:</b> Make the font bold where the fathers name is greater than 8 chars and there are 2 kids</p>
<p><b><a href="http://www.box.net/shared/c0gz4hqli6">Download Source Code &#8211; 423Kb</a></b></p>
<p><b>Make the families background red where there are no kids</b><br />
Binding is very flexible in WPF you can easily bind to any of the properties available in the class. Like in this scenario we need to check if the kids count in the family is 0. For this we need to declare a style and bind our RowStyle of the grid to the defined style. Lets work on it.<br />
Lets declare a style and name it as CheckKids and check for the kids.count condition for 0. </font></p>
<pre style="overflow:auto;width:95%;color:#000000;line-height:14px;border:#999999 1px dashed;font-size:15px;padding:5px;">
<font color="#008000" size="2"><!--style to display family in Red where there are no kids-->········</font>
<font color="#0000FF" size="2">&#60;</font><font color="#A31515" size="2">Style</font><font color="#FF0000" size="2"> x</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">Key</font><font color="#0000FF" size="2">="CheckKids"</font><font color="#FF0000" size="2"> TargetType</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">x</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">Type</font><font color="#FF0000" size="2"> my</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">DataGridRow</font><font color="#0000FF" size="2">}"&#62;············
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">DataTrigger</font><font color="#FF0000" size="2"> Binding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> Kids</font><font color="#0000FF" size="2">.</font><font color="#FF0000" size="2">Count</font><font color="#0000FF" size="2">}"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="0"&#62;····················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Setter</font><font color="#FF0000" size="2"> Property</font><font color="#0000FF" size="2">="Background"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="Red"/&#62;················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">DataTrigger</font><font color="#0000FF" size="2">&#62;············
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;········
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style</font><font color="#0000FF" size="2">&#62;</font>
</pre>
<p><font face="Verdana,Arial,Helvetica,sans-serif" color="#000000" size="2">In the collection Mr.Ramiayaa has no kids so background of his row is made red.</p>
<p><a href="http://codingsense.wordpress.com/files/2009/11/nokids3.jpg"><img src="http://codingsense.wordpress.com/files/2009/11/nokids3.jpg" alt="" title="NoKids" width="481" height="198" class="alignnone size-full wp-image-385" /></a></p>
<p><b>Hide the families where the name of the father is less than 8 chars</b><br />
Now comes the challange how will you check fatherName &#60; 8 in XAML. Pretty tricky right. Here is a simple method to be followed. What if we have another property in our class which returns true or false by checking the fathername.length. It will help us to acheive our goal. </p>
<p>Lets Declare a property in Father class and name it as IsLengthLessThanEight, which will return if the father name is less than 8 char or not. It will look like</p>
<pre style="overflow:auto;width:95%;color:#000000;line-height:14px;border:#999999 1px dashed;font-size:15px;padding:5px;">
<font color="#0000FF" size="2">public <font color="#0000FF" size="2">bool</font></font><font size="2"> IsLengthLessThanEight
{</font>
<font color="#0000FF" size="2">get </font><font size="2">{ </font><font color="#0000FF" size="2">return</font><font size="2"> (FirstName.Length &#60; 8); }
}</font>
</pre>
<p>By this we can be very sure that we can write our own properties and bind it to make anything possible.<br />
Now lets declare the style and name it FatherNameLessEightChar and bind it to our declared property IsLengthLessThanEight<br />
and check the desired condition.</p>
<pre style="overflow:auto;width:95%;color:#000000;line-height:14px;border:#999999 1px dashed;font-size:15px;padding:5px;">
<font color="#008000" size="2"><!--Style to make family visibility= hidden where fathers name is less than 8 chars-->········</font>
<font color="#0000FF" size="2">&#60;</font><font color="#A31515" size="2">Style</font><font color="#FF0000" size="2"> x</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">Key</font><font color="#0000FF" size="2">="FatherNameLessEightChar"</font><font color="#FF0000" size="2"> TargetType</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">x</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">Type</font><font color="#FF0000" size="2"> my</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">DataGridRow</font><font color="#0000FF" size="2">}"&#62;············
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">DataTrigger</font><font color="#FF0000" size="2"> Binding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> IsLengthLessThanEight</font><font color="#0000FF" size="2">}"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="True"&#62;····················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Setter</font><font color="#FF0000" size="2"> Property</font><font color="#0000FF" size="2">="Visibility"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="Hidden"/&#62;················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">DataTrigger</font><font color="#0000FF" size="2">&#62;············
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;········
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style</font><font color="#0000FF" size="2">&#62;</font>
</pre>
<p>In the collection we have only one father who has the name less than 8 that is Mr.Rocky that name is to be hidden.</p>
<p><a href="http://codingsense.wordpress.com/files/2009/11/lessthaneightchar1.jpg"><img src="http://codingsense.wordpress.com/files/2009/11/lessthaneightchar1.jpg" alt="" title="LessThanEightChar" width="458" height="209" class="alignnone size-full wp-image-386" /></a></p>
<p><font face="Verdana,Arial,Helvetica,sans-serif" color="#000000" size="2"><br />
<b>Make the font bold where the fathers name is greater than 8 chars and there are 2 kids</b><br />
Here comes the next challange how will we check more than one condition in XAML. Is it possible or should we declare another property and check 2 conditions in our class. For this we have MultiDataTrigger which will help us to check multiple conditions in XAML and set property accordingly. Cool.<br />
Lets declare a style and name it CheckNameAndKidsCount and use the MultiDataTrigger.</p>
<pre style="overflow:auto;width:95%;color:#000000;line-height:14px;border:#999999 1px dashed;font-size:15px;padding:5px;">
<font color="#0000FF" size="2">&#60;</font><font color="#A31515" size="2">Style</font><font color="#FF0000" size="2"> x</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">Key</font><font color="#0000FF" size="2">="CheckNameAndKidsCount"</font><font color="#FF0000" size="2"> TargetType</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">x</font><font color="#0000FF" size="2">:</font><font color="#A31515" size="2">Type</font><font color="#FF0000" size="2"> my</font><font color="#0000FF" size="2">:</font><font color="#FF0000" size="2">DataGridRow</font><font color="#0000FF" size="2">}"&#62;············
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">MultiDataTrigger</font><font color="#0000FF" size="2">&#62;····················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">MultiDataTrigger.Conditions</font><font color="#0000FF" size="2">&#62;························
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Condition</font><font color="#FF0000" size="2"> Binding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> IsLengthLessThanEight</font><font color="#0000FF" size="2">}"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="False"/&#62;························
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Condition</font><font color="#FF0000" size="2"> Binding</font><font color="#0000FF" size="2">="{</font><font color="#A31515" size="2">Binding</font><font color="#FF0000" size="2"> Kids</font><font color="#0000FF" size="2">.</font><font color="#FF0000" size="2">Count</font><font color="#0000FF" size="2">}"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="2"/&#62;····················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">MultiDataTrigger.Conditions</font><font color="#0000FF" size="2">&#62;····················
<font color="#0000FF" size="2">&#60;</font></font><font color="#A31515" size="2">Setter</font><font color="#FF0000" size="2"> Property</font><font color="#0000FF" size="2">="FontWeight"</font><font color="#FF0000" size="2"> Value</font><font color="#0000FF" size="2">="Bold"/&#62;················
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">MultiDataTrigger</font><font color="#0000FF" size="2">&#62;············
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style.Triggers</font><font color="#0000FF" size="2">&#62;········
<font color="#0000FF" size="2">&#60;/</font></font><font color="#A31515" size="2">Style</font><font color="#0000FF" size="2">&#62;</font>
</pre>
<p><font face="Verdana,Arial,Helvetica,sans-serif" color="#000000" size="2"><br />
Here we check both the conditions i.e First we check if father name is greater than 8 char with the help of the IsLengthLessThanEight that we have defined and next condition we check if the kids count is 2 or not. If both the conditions are satisfied then the font of the family is made bold.<br />
In our collection we have Mr.Balasubramanyam whose name is greater than 8 char and has 2 childrens so his row should be made bold.</p>
<p><a href="http://codingsense.wordpress.com/files/2009/11/twokidsandbigname1.jpg"><img src="http://codingsense.wordpress.com/files/2009/11/twokidsandbigname1.jpg" alt="" title="TwoKidsAndBigName" width="475" height="217" class="alignnone size-full wp-image-387" /></a></p>
<p>Wow all the scenarios have completed and we have got the desired output for all of them. Thanks to DataTrigger for simplifying the life. In this similar fashion we can declare style trigger and data trigger to make various styles depending on the data that is bound.</p>
<p><b>References :</b><br />
<a href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx">http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx</a></p>
<p>Cheers <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Naveen Prabhu</p>
<p></font></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Depreciation using Declining Balance Method]]></title>
<link>http://zamjad.wordpress.com/2009/11/24/depreciation-using-declining-balance-method/</link>
<pubDate>Wed, 25 Nov 2009 04:45:29 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/24/depreciation-using-declining-balance-method/</guid>
<description><![CDATA[We just saw how to calculate the depreciation using straight line method, now we are going to calcul]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We just saw how to calculate the depreciation using straight line method, now we are going to calculate depreciation using another method, i.e. Decline Balance method. This is also known as double declining balance method. Here are are again going to use progress bar in the list control. </p>
<p>Here is a code to calculate the depreciation using declining balance method.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> iIndex = 0; iIndex &#60; year; iIndex++)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: 	depExpense = bookValue * percentage * 2;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: 	<span style="color:#0000ff;">if</span> (bookValue - depExpense &#60; scrap)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: 	{
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: 		depExpense = bookValue - scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: 		bookValue = scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: 	<span style="color:#0000ff;">else</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: 	{
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 		bookValue -= depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: 	accDepreciation += depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: 	DepreciationInfo dpInfo = <span style="color:#0000ff;">new</span> DepreciationInfo();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18: 	dpInfo.Year = (iIndex + 1);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19: 	dpInfo.Depreciation = depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20: 	dpInfo.AccDepreciation = accDepreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21: 	dpInfo.BookValue = bookValue;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22: 	dpInfo.Percentage = (bookValue * 100) / cost; ;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24: 	depreciation.Add(dpInfo);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26: </pre>
</pre>
<p>Here is a complete XAML code of the project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;Depreciation.Window1&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:     <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:     <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:     <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;Depreciation&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;400&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;600&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">Background</span>=<span style="color:#0000ff;">&#34;AliceBlue&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;4*&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter Cost of Fixed Asset<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtCost&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter life Span<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtYear&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter Scrap Value<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtScrapValue&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListView</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;3&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">ColumnSpan</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;list&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">HorizontalContentAlignment</span>=<span style="color:#0000ff;">&#34;Stretch&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListView.View</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridView.ColumnHeaderTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:                             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Border</span> <span style="color:#ff0000;">BorderBrush</span>=<span style="color:#0000ff;">&#34;Brown&#34;</span> <span style="color:#ff0000;">BorderThickness</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">CornerRadius</span>=<span style="color:#0000ff;">&#34;5&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Border.Background</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:                                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">LinearGradientBrush</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:                                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GradientStop</span> <span style="color:#ff0000;">Offset</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Color</span>=<span style="color:#0000ff;">&#34;Wheat&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:                                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GradientStop</span> <span style="color:#ff0000;">Offset</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Color</span>=<span style="color:#0000ff;">&#34;LightCoral&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:                                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">LinearGradientBrush</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:                                 <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Border.Background</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Foreground</span>=<span style="color:#0000ff;">&#34;Blue&#34;</span> <span style="color:#ff0000;">FontSize</span>=<span style="color:#0000ff;">&#34;14&#34;</span> <span style="color:#ff0000;">FontWeight</span>=<span style="color:#0000ff;">&#34;Bold&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Text</span>=<span style="color:#0000ff;">&#34;{Binding}&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:                             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Border</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:                         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridView.ColumnHeaderTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Year&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=Year}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Depreciation&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=Depreciation}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Accumulated Depreciation&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=AccDepreciation}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Book Value&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=BookValue}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Percentage&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn.CellTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:                             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ProgressBar</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;50&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;20&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Minimum</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Maximum</span>=<span style="color:#0000ff;">&#34;100&#34;</span> <span style="color:#ff0000;">Value</span>=<span style="color:#0000ff;">&#34;{Binding Percentage}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:                             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:                         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridViewColumn.CellTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridViewColumn</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:                 <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListView.View</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;10&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;75&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;btnCalculate&#34;</span> <span style="color:#ff0000;">Click</span>=<span style="color:#0000ff;">&#34;btnCalculate_Click&#34;</span><span style="color:#0000ff;">&#62;</span>Calculate<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Button</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;10&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;75&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;btnExit&#34;</span> <span style="color:#ff0000;">Click</span>=<span style="color:#0000ff;">&#34;btnExit_Click&#34;</span><span style="color:#0000ff;">&#62;</span>Exit<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Button</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 60: </pre>
</pre>
<p>Here is complete C# code of the project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">using</span> System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">using</span> System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">using</span> System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">using</span> System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">using</span> System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">using</span> System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">using</span> System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">using</span> System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">using</span> System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">using</span> System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: <span style="color:#0000ff;">using</span> System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: <span style="color:#0000ff;">using</span> System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">using</span> System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: <span style="color:#0000ff;">namespace</span> Depreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:     <span style="color:#808080;">/// &#60;summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:     <span style="color:#808080;">/// Interaction logic for Window1.xaml</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     <span style="color:#808080;">/// &#60;/summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     <span style="color:#0000ff;">public</span> partial <span style="color:#0000ff;">class</span> Window1 : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         List&#60;DepreciationInfo&#62; depreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> year;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">double</span> cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">double</span> scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:         <span style="color:#0000ff;">public</span> Window1()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:             depreciation = <span style="color:#0000ff;">new</span> List&#60;DepreciationInfo&#62;();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> btnExit_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:             Close();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> btnCalculate_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:             depreciation.Clear();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:             year = Convert.ToInt32(txtYear.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:             cost = Convert.ToDouble(txtCost.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:             scrap = Convert.ToDouble(txtScrapValue.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:             <span style="color:#0000ff;">if</span> (year &#60;= 0)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:                 MessageBox.Show(&#34;<span style="color:#8b0000;">Number of years can not be zero or negative.</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:                 <span style="color:#0000ff;">return</span>;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:             <span style="color:#0000ff;">if</span> (cost &#60;= 0 &#124;&#124; scrap &#60;= 0)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:                 MessageBox.Show(&#34;<span style="color:#8b0000;">Either Cost or Scrap value is not correct.</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:                 <span style="color:#0000ff;">return</span>;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59:             <span style="color:#0000ff;">double</span> percentage = 100 / year;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 60:             percentage /= 100;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 61:             <span style="color:#0000ff;">double</span> accDepreciation = 0;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 62:             <span style="color:#0000ff;">double</span> bookValue = cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 63:             <span style="color:#0000ff;">double</span> depExpense = 0;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 64:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 65:             <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> iIndex = 0; iIndex &#60; year; iIndex++)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 66:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 67:                 depExpense = bookValue * percentage * 2;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 68:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 69:                 <span style="color:#0000ff;">if</span> (bookValue - depExpense &#60; scrap)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 70:                 {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 71:                     depExpense = bookValue - scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 72:                     bookValue = scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 73:                 }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 74:                 <span style="color:#0000ff;">else</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 75:                 {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 76:                     bookValue -= depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 77:                 }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 78:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 79:                 accDepreciation += depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 80:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 81:                 DepreciationInfo dpInfo = <span style="color:#0000ff;">new</span> DepreciationInfo();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 82:                 dpInfo.Year = (iIndex + 1);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 83:                 dpInfo.Depreciation = depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 84:                 dpInfo.AccDepreciation = accDepreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 85:                 dpInfo.BookValue = bookValue;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 86:                 dpInfo.Percentage = (bookValue * 100) / cost; ;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 87:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 88:                 depreciation.Add(dpInfo);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 89:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 90:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 91:             list.ItemsSource = depreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 92:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 93:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 94:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 95:     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> DepreciationInfo
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 96:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 97:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Year
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 98:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 99:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">100:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Depreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">101:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">102:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">103:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> AccDepreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">104:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">105:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">106:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> BookValue
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">107:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">108:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">109:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Percentage
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">110:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">111:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">112: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">113: </pre>
</pre>
<p>Here is the output of the program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/depreciationoutput.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="DepreciationOutput" border="0" alt="DepreciationOutput" src="http://zamjad.files.wordpress.com/2009/11/depreciationoutput_thumb.gif?w=600&#038;h=400" width="600" height="400" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[MEF in MVVM]]></title>
<link>http://maonet.wordpress.com/2009/11/24/mef-in-mvvm-with-wcf/</link>
<pubDate>Tue, 24 Nov 2009 18:24:24 +0000</pubDate>
<dc:creator>Frank Mao</dc:creator>
<guid>http://maonet.wordpress.com/2009/11/24/mef-in-mvvm-with-wcf/</guid>
<description><![CDATA[I read a post about MEF vs. IOC which cleared the confusion: MEF should be used external of app, whi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I read a post about <a href="http://mef.codeplex.com/">MEF</a> vs. IOC which cleared the confusion: MEF should be used external of app, while IOC should be used internally.</p>
<p>Good point. I have been struggling with how to separate my view and view model correctly in WPF app for a long time.   In fact Bil Simer already suggested that MEF is perfect fit in MVVM/Presentation Model last year during the Edmonton Code Camp 2008.</p>
<p>Ideally, all view models can be compiled into a separated assembly and put into specific folder to be imported by UI views!</p>
<p>Some code changes during my code conversion include:</p>
<ul>
<li>Remove ctor args from view model, I haven&#8217;t figure out how to feed ctor args when MEF importing. This is not easy as auto-wiring in IOC. I ended up with a separate initialize method in each view model, which is not too bad, because I have to call wireUpViewModel from view anyway, this Initialize method has a perfect place to put.</li>
<li>I&#8217;m still not sure where should I put Container.Compose() method, because this method needs the instance the object to be imported into, I think compose as needed is better for WPF app.</li>
<li>Shared mode is the default behavior for export and import, it messed up my event handling code, (true, I didn&#8217;t do -= before +=). I had to explicitly add this everywhere.</li>
</ul>
<blockquote>
<pre>[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
or
[Import(typeof(NewRequestTypeViewModel), RequiredCreationPolicy = CreationPolicy.NonShared)]</pre>
</blockquote>
<p>Code:</p>
<pre class="brush: csharp;">
    public partial class TemplateEditShell : Window{

        private CompositionContainer _mefContainer;

        public TemplateEditShell()
        {
            InitializeComponent();
            InitialzieMEF();
        }

        private void InitialzieMEF()
        {
            var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
            _mefContainer = new CompositionContainer(catalog);
        }

        private void btnEditItemList_Click(object sender, RoutedEventArgs e)
        {
            var proxy = ObjectFactory.GetInstance&#60;IRequestManagementAdminService&#62;();
            var view = new EditRequestTypeItemListView(_viewModel.SelectedRequestType, proxy);
            _mefContainer.ComposeParts(view);
            view.WireUpViewModel();
            view.ShowDialog();
        }
  }

    public partial class EditRequestTypeItemListView : Window
    {
        private readonly RequestTypeDto _requestTypeDto;
        private readonly IRequestManagementAdminService _proxy;

        [Import]
        public IEditRequestTypeItemListViewModel EditRequestTypeItemListViewModel { get; set; }

        public EditRequestTypeItemListView(RequestTypeDto requestTypeDto, IRequestManagementAdminservice proxy)
        {
            _requestTypeDto = requestTypeDto;
            _proxy = proxy;
            InitializeComponent();

            // Can't wire up in ctor, coz MEF import hasn't start/finish yet.
//            WireUpViewModel();
        }

        public void WireUpViewModel()
        {
            DataContext = EditRequestTypeItemListViewModel;

            EditRequestTypeItemListViewModel.Initialize(_proxy, _requestTypeDto);

            EditRequestTypeItemListViewModel.RequestShowMessage += (o, arg) =&#62; MessageBox.Show(arg.EventData);

        }
    }

    [Export(typeof(IEditRequestTypeItemListViewModel))]
    public class EditRequestTypeItemListViewModel : ViewModelBase, IEditRequestTypeItemListViewModel
    {
        private IRequestManagementAdminContract _proxy;
        private RequestTypeDto _currentRequestType;

        public RequestTypeItemDto SelectedRequestTypeItem { get; set; }

        public ObservableCollection ItemList { get; set; }

        public EditRequestTypeItemListViewModel()
        {
        }

        public void Initialize(IRequestManagementAdminContract proxy, RequestTypeDto currentRequestType)
        {
            _proxy = proxy;
            _currentRequestType = currentRequestType;

            ItemList = new ObservableCollection(proxy.FindAllRequestTypeItems(currentRequestType.Id));

            SelectedRequestTypeItem = ItemList.FirstOrDefault();
        }
  }
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Numeric to string]]></title>
<link>http://terjeisaksen.wordpress.com/2009/11/24/numeric-to-string/</link>
<pubDate>Tue, 24 Nov 2009 16:25:43 +0000</pubDate>
<dc:creator>Terje Isaksen</dc:creator>
<guid>http://terjeisaksen.wordpress.com/2009/11/24/numeric-to-string/</guid>
<description><![CDATA[Binding a textbox to a numeric source and formatting it is done by &lt;TextBox Text="{Binding Path=F]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Binding a textbox to a numeric source and formatting it is done by</p>
<pre><span style="font-size:small;">&#60;TextBox Text="{Binding Path=Fieldname, StringFormat=formatstring}"/&#62;
</span></pre>
<p>where &#8220;formatstring&#8221; can for example be any of following:</p>
<p>Fn &#8211; fixed point number  &#8211; where n= number of decimals<br />
Pn &#8211; percentage (value is multiplied with 100 and displayed with a %-symbol) &#8211; where n = number of decimals<br />
Dn &#8211; integer &#8211; where n= number of digits<br />
Nn &#8211; number with decimals and group separators, where n=number of decimals<br />
Xn &#8211; hexadecimal integer &#8211; where n= number of digits</p>
<p>It can also be a string of custom numeric format characters inside a pair of single quotes which for example can be:</p>
<p>0 &#8211; zero placeholder, gives a digit if present &#8211; zero otherwise<br />
# &#8211; digit placeholder, gives a digit if present, nothing otherwise<br />
. &#8211; decimal point &#8211; determines where the decimal seperator should be<br />
, &#8211; group separator &#8211; gives the localized group separator. Can also be used at the end to divide the number with 1000 for each comma<br />
% &#8211; percentage placeholder &#8211; if at the end &#8211; multiplies number with 100 and gives percentage symbol at end</p>
<p>See more at:</p>
<p><a title="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx</a><br />
<a title="http://msdn.microsoft.com/en-us/library/0c899ak8.aspx" href="http://msdn.microsoft.com/en-us/library/0c899ak8.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/0c899ak8.aspx</a></p>
<p><a title="http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx" href="http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx" target="_blank">http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx</a></p>
<pre><span style="font-size:small;">
</span></pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Simple Usage of Data Grid Control in WPF 4]]></title>
<link>http://zamjad.wordpress.com/2009/11/23/simple-usage-of-data-grid-control-in-wpf-4/</link>
<pubDate>Tue, 24 Nov 2009 04:11:17 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/23/simple-usage-of-data-grid-control-in-wpf-4/</guid>
<description><![CDATA[WPF 4.0 introduced lots of new feature and one of them is Data Grid control. Here we are going to st]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>WPF 4.0 introduced lots of new feature and one of them is Data Grid control. Here we are going to study the simple usage of Data grid control. Here is a class diagram of DataGrid.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/datagrid.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="DataGrid" border="0" alt="DataGrid" src="http://zamjad.files.wordpress.com/2009/11/datagrid_thumb.gif?w=153&#038;h=214" width="153" height="214" /></a> </p>
<p>Here is a XAML code of this project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;grid.MainWindow&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:         <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:         <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:         <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;Example of Data Grid&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;300&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;300&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataGrid</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;grid&#34;</span> <span style="color:#ff0000;">AlternationCount</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Background</span>=<span style="color:#0000ff;">&#34;AliceBlue&#34;</span> <span style="color:#ff0000;">AlternatingRowBackground</span>=<span style="color:#0000ff;">&#34;LightGreen&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataGrid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: </pre>
</pre>
<p>We just create a list of our user define class and assign it to the grid class. Here is a complete C# code of this project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">using</span> System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">using</span> System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">using</span> System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">using</span> System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">using</span> System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">using</span> System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">using</span> System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">using</span> System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">using</span> System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">using</span> System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: <span style="color:#0000ff;">using</span> System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: <span style="color:#0000ff;">using</span> System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">using</span> System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: <span style="color:#0000ff;">namespace</span> grid
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:     <span style="color:#808080;">/// &#60;summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:     <span style="color:#808080;">/// Interaction logic for MainWindow.xaml</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     <span style="color:#808080;">/// &#60;/summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     <span style="color:#0000ff;">public</span> partial <span style="color:#0000ff;">class</span> MainWindow : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">private</span> List&#60;Student&#62; student;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         <span style="color:#0000ff;">public</span> MainWindow()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:             student = <span style="color:#0000ff;">new</span> List&#60;Student&#62;();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:             student.Add(<span style="color:#0000ff;">new</span> Student(10, &#34;<span style="color:#8b0000;">Bob</span>&#34;, &#34;<span style="color:#8b0000;">Smith</span>&#34;));
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:             student.Add(<span style="color:#0000ff;">new</span> Student(25, &#34;<span style="color:#8b0000;">James</span>&#34;, &#34;<span style="color:#8b0000;">Brown</span>&#34;));
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:             student.Add(<span style="color:#0000ff;">new</span> Student(15, &#34;<span style="color:#8b0000;">Joe</span>&#34;, &#34;<span style="color:#8b0000;">Martin</span>&#34;));
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:             student.Add(<span style="color:#0000ff;">new</span> Student(12, &#34;<span style="color:#8b0000;">Dona</span>&#34;, &#34;<span style="color:#8b0000;">Taylor</span>&#34;));
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:             student.Add(<span style="color:#0000ff;">new</span> Student(18, &#34;<span style="color:#8b0000;">Peter</span>&#34;, &#34;<span style="color:#8b0000;">Brian</span>&#34;));
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:             grid.ItemsSource = student;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Student
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:         <span style="color:#0000ff;">public</span> Student(<span style="color:#0000ff;">int</span> id, String firstName, String lastName)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:             ID = id;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:             FirstName = firstName;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:             LastName = lastName;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> ID
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:         <span style="color:#0000ff;">public</span> String FirstName
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:         <span style="color:#0000ff;">public</span> String LastName
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58: </pre>
</pre>
<p>Here is the output of this project.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/datagridoutput.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="DataGridOutput" border="0" alt="DataGridOutput" src="http://zamjad.files.wordpress.com/2009/11/datagridoutput_thumb.gif?w=300&#038;h=300" width="300" height="300" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[More about ListBox in Wpf]]></title>
<link>http://abs59il.wordpress.com/2009/11/23/more-about-listbox-in-wpf/</link>
<pubDate>Mon, 23 Nov 2009 21:21:37 +0000</pubDate>
<dc:creator>abs59il</dc:creator>
<guid>http://abs59il.wordpress.com/2009/11/23/more-about-listbox-in-wpf/</guid>
<description><![CDATA[דוגמא להורדה &#8230; דבר ראשון ניצור , נתוני דמה , Collection עם שתי מאפיינים – תמונה וכותרת , נגרור]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><b><a href="http://dl.dropbox.com/u/1223589/MoreAboutLostBox.rar" target="_blank">דוגמא להורדה &#8230;</a></b></p>
<p>דבר ראשון ניצור , נתוני דמה , Collection עם שתי מאפיינים – תמונה וכותרת , נגרור את את אוסף הדמה ונגרור הישר אל הלוח , הפעולה תיצור ListBox עם הפריטים .</p>
<h3>DataTemplate</h3>
<p>ה ListBox שקיבלנו הוא בסיסי והיינו רוצים לעצב את התוכן בצורה שמתאימה לנו , ולצורך כך Wpf&#160; מעמידה לרשותנו מספר תבניות שאותן נוכל לעצב . הראשונה היא DataTemplate וכמו שהתחלתי להגיד היא מתייחסת ל Data , היא מאפשרת לנו לעצב כל Data !? נשאלת גם השאלה מאיפה מגיע אותו Data ?&#160; ..</p>
<p>ישנם פקדים מסוימים שמטרתם להציג תוכן והם מכילים רכיב שנקרא ContentPresenter&#160; , שכל תפקידו הוא להציג תוכן , כל תוכן טקסט תמונה או כל פקד אחר , כאשר אנו מציגים Data בסיסי ( שאין לו ייצוג ויזואלי ) ה-DataTemplate מספק את הייצוג הוויזואלי הזה .. .</p>
<p>נחזור לעבודה שלנו , לאחר שגררנו את האוסף ונוצר לנו ListBox , אם נבחן את ה-Xaml נראה שנוצר לנו גם DataTemplate בסיסי ועכשיו נרצה לשנות אותו .. </p>
<p>כפתור ימני על ה-ListBox ו-</p>
<p><a href="http://abs59il.files.wordpress.com/2009/11/1.jpg"><img style="display:inline;border-width:0;" title="1" border="0" alt="1" src="http://abs59il.files.wordpress.com/2009/11/1_thumb.jpg?w=536&#038;h=87" width="536" height="87" /></a> </p>
<p>נבחר ב Edit Current כי כמו שכבר אמרתי למעלה , לאחר הגרירה נוצר לנו DataTemplate בסיסי .. </p>
<p>ה Template מכיל StackPanel עם תווית טקסט ותמונה , נשנה קצת את הערכים כדי שיתאימו למה שאנו צריכים .. ( מרכוז , הדגשה של כותרת ) </p>
<p><strong>חלק מהמאפיינים מוקפים במסגרת צהובה , מכיוון שהערך שלהם מגיע מה Data באמצעות DataBinding .. </strong></p>
<p>&#160;<a href="http://abs59il.files.wordpress.com/2009/11/3.jpg"><img style="display:inline;margin-left:0;margin-right:0;border-width:0;" title="3" border="0" alt="3" src="http://abs59il.files.wordpress.com/2009/11/3_thumb.jpg?w=244&#038;h=206" width="244" height="206" /></a></p>
<p>אני קיבלתי את זה … </p>
<p><a href="http://abs59il.files.wordpress.com/2009/11/2.jpg"><img title="2" border="0" alt="2" src="http://abs59il.files.wordpress.com/2009/11/2_thumb.jpg?w=167&#038;h=244" width="167" height="244" /></a></p>
<h2></h2>
<h3>ContainerStyle</h3>
<p>ה- DataTemplate התעסק בעיצוב של ה-Data , אבל אם אני רוצה לעצב את ה ListItem עצמו ..? אולי להוסיף לו גבול , הצללה , או כל דבר שלא קשור ישירות ל-Data, כדי לבצע את זה נצטרך לערוך את ה- ItemContainerStyle העבודה דיי דומה ל DataTemplate , </p>
<p>&#160;</p>
<p><a href="http://abs59il.files.wordpress.com/2009/11/4.jpg"><img style="display:inline;border-width:0;" title="4" border="0" alt="4" src="http://abs59il.files.wordpress.com/2009/11/4_thumb.jpg?w=460&#038;h=84" width="460" height="84" /></a> </p>
<p>ניתן לראות שפה כבר רואים את ה ContentPresenter שהזכרתי למעלה .. כרגע אותו Content עטוף ב Border , ואנחנו לא רואים את זה מכיוון שלא הוגדרה מברשת צבע&#160; , ולכן , נבחר<a href="http://abs59il.files.wordpress.com/2009/11/8.jpg"><img title="8" border="0" alt="8" src="http://abs59il.files.wordpress.com/2009/11/8_thumb.jpg?w=244&#038;h=208" width="244" height="208" /></a> </p>
<p>מברשת צבע שחורה , ושנה את ערכי ה Border ל-1 , עכשיו כל ListBoxItem יהיה מוקף בגבול שחור .. </p>
<p><strong>חלק מהערכים יהיו &#34;נעולים&#34; ב DataBinding ולכן יש לבצע Reset על יד לחיצה על הנקודה הצהובה שבצד ועל הפקודה המתאימה . </strong></p>
<h3>ItemsPanel</h3>
<p>מה שמפריע לי עכשיו הוא , שכל ה- Items מופיעים מלמעלה למטה , הייתי רוצה התנהגות של WrapPanel , .. ולכן שוב כפתור ימני ..</p>
<p><a href="http://abs59il.files.wordpress.com/2009/11/9.jpg"><img title="9" border="0" alt="9" src="http://abs59il.files.wordpress.com/2009/11/9_thumb.jpg?w=465&#038;h=96" width="465" height="96" /></a></p>
<p>נמחק את הרכיב הבודד שקיים בעץ , ונשים במקומו WrapPanel .. </p>
<p><a href="http://abs59il.files.wordpress.com/2009/11/10.jpg"><img style="border-width:0;" title="10" border="0" alt="10" src="http://abs59il.files.wordpress.com/2009/11/10_thumb.jpg?w=459&#038;h=123" width="459" height="123" /></a></p>
<p>זה מה שקיבלתי , אבל לא בדיוק מה שרציתי, מכיוון שה-Control מורכב מפס-גלילה .. ( לא מתאים ) </p>
<h3>ControlTemplate</h3>
<p>שוב כפתור ימני .. והפעם נערוך את ה ControlTemplate , ז&#34;א שיש לנו לשנות כל דבר ברכיבים שמרכיבים את הפקד ..!</p>
<p>&#160;<a href="http://abs59il.files.wordpress.com/2009/11/11.jpg"><img style="display:inline;border-width:0;" title="11" border="0" alt="11" src="http://abs59il.files.wordpress.com/2009/11/11_thumb.jpg?w=244&#038;h=103" width="244" height="103" /></a></p>
<p>נרצה לערוך Copy ולא את הפקד עצמו .. </p>
<p>&#160;<a href="http://abs59il.files.wordpress.com/2009/11/12.jpg"><img style="display:inline;border-width:0;" title="12" border="0" alt="12" src="http://abs59il.files.wordpress.com/2009/11/12_thumb.jpg?w=244&#038;h=138" width="244" height="138" /></a> </p>
<p>כל מה שנותר הוא להסיר את פס הגלילה .. ( ולוודא שלא מסירים גם את ה ItemPresenter – בערך כמו ContentPresenter רק לאוספים ) … </p>
<p>זה הכל בנתיים .. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Сапер для WPF]]></title>
<link>http://knoxknox.wordpress.com/2009/11/23/%d1%81%d0%b0%d0%bf%d0%b5%d1%80-%d0%b4%d0%bb%d1%8f-wpf/</link>
<pubDate>Mon, 23 Nov 2009 20:36:21 +0000</pubDate>
<dc:creator>knox</dc:creator>
<guid>http://knoxknox.wordpress.com/2009/11/23/%d1%81%d0%b0%d0%bf%d0%b5%d1%80-%d0%b4%d0%bb%d1%8f-wpf/</guid>
<description><![CDATA[«Дабл-сапер»: Играют два игрока на большом поле. Каждый игрок может не только разминировать клетки, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>«Дабл-сапер»:<br />
Играют два игрока на большом поле. Каждый игрок может не только разминировать клетки, но и ставить свои мины(!). При этом он видит их положение, аналогично тому как помеченные клетки с минами. Мины можно ставить только на закрытые клетки. Если противник поставил мину, то для соседних отрытых пересчитывается кол-во мин. Это нужно для того, чтобы соперник видел, что картина как-то изменилась и ему нужно подумать над ней еще разок.<br />
Игрок побеждает, если:<br />
— его противник подорвался<br />
— если никто не взорвался, и он открыл больше клеток.</p>
<p>В чем смак игры: с одной стороны идет жесктое соревнование на время — вы на своем поле видите, как ваш противник открывает клетки (дополнительно в углу можно показывать сколько клеток вы отркыли, или же процент). В тоже время спешить нелья — одно неловкое движение и вы проиграли. Нужно очень четко следить за действиями противника — может оказаться так, что он откроет какую-то клетку, рядом с которой лежит «клондайк» — то есть свободная зона, которую вы можете у него перехватить и тем самым урвать у него клетки.<br />
Но помимо этого можно делать «пакости» — поймать противника на невнимательности. Пока не продумал этот момент, но возможно надо ограничить кол-во мин, которые может поставить игрок. Чтобы это не порождало тупиков в игре.</p>
<p>Кстати, не обязательно играть в двоем — можно и большей компанией.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Вариант — две команды по несколько игроков (минимум по одному, максимум, например, по 5 в каждой команде) разминируют одно и то же поле. Разминированная часть и отмеченные мины засчитываются в пользу той или другой команды, так можно видеть, кто побеждает, например «23% — 34%, 12мин — 20мин». При этом начальное поле имеет слева и справа пустую область, то есть, одна команда начинает открывать поле с левой стороны, другая с правой, и обе видят в самом начале открытую границу с указанным количеством мин на своей границе.</p>
<p>Действительно, многое зависит от удачи, но есть место и для стратегии: например, слабых игроков в каждой команде можно использовать для проверки спорных мест — «Ваня, проверь вот здесь». Ваня подорвался, значит мина была, но остальная команда продолжает разминирование. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Vista, 7, IE9 e DirectX]]></title>
<link>http://invista.wordpress.com/2009/11/23/viata-7-ie9-e-directx/</link>
<pubDate>Mon, 23 Nov 2009 13:21:45 +0000</pubDate>
<dc:creator>Max</dc:creator>
<guid>http://invista.wordpress.com/2009/11/23/viata-7-ie9-e-directx/</guid>
<description><![CDATA[Una delle cose più belle di Vista è il fatto che Microsoft ha praticamente costretto i produttori a ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Una delle cose più belle di Vista è il fatto che Microsoft ha praticamente costretto i produttori a mettere nei PC delle schede video decenti con il supporto DirectX. Questo abilita e migliora una serie di funzionalità tra cui WDDM e WPF.</p>
<p>Questo è uno dei fattori che sta facendo fare un salto di qualità all’esperienza dell’utente (tralasciando i driver bacati, ovviamente). E’, secondo me, anche uno dei fattori determinanti che mettono sullo stesso piano Windows 7 e Mac OSX. </p>
<p>Ora si apprende che IE9, come Silverlight, userà l’hardware grafico per accelerare il rendering. Che altro dire se non che è una buona cosa!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WPF Binding Cheat Sheet]]></title>
<link>http://diptimayapatra.wordpress.com/2009/11/23/wpf-binding-cheat-sheet/</link>
<pubDate>Mon, 23 Nov 2009 10:15:04 +0000</pubDate>
<dc:creator>dpatra1982</dc:creator>
<guid>http://diptimayapatra.wordpress.com/2009/11/23/wpf-binding-cheat-sheet/</guid>
<description><![CDATA[Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won&#8217;t work for]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><h1>Introduction</h1>
<p>This is an article on WPF Binding Cheat Sheet. Some of the Binding won&#8217;t work for Silverlight 3.</p>
<div>
<table style="border-collapse:collapse;" border="0">
<col span="1"></col>
<col span="1"></col>
<tbody>
<tr style="background:#4f81bd;height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-left:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;" colspan="2"><span style="color:white;"><strong>Basic Binding</strong></span> </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to current DataContext.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding Name}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the &#8220;Name&#8221; proeprty of the current DataContext.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">{Bindind Name.Length}</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the Length property of the object in the Name property of the current DataContext </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding ElementName=SomeTextBox, Path=Text}</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the &#8220;Text&#8221; property of the element XAML element with name=&#8221;SomeTextBox&#8221; or x:Name=&#8221;SomeTextBox&#8221;.</td>
</tr>
</tbody>
</table>
</div>
<div>
<table style="border-collapse:collapse;" border="0">
<col span="1"></col>
<col span="1"></col>
<tbody>
<tr style="background:#4f81bd;height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-left:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;" colspan="2"><span style="color:white;"><strong>XML Binding</strong></span></td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding Source={StaticResource BooksData} XPath=/books/book}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind the result of XPath query &#8220;/books/book&#8221; from the XML in the XmlDataProvider in a parent&#8217;s &#8220;Resources&#8221; elememt with x:Key=&#8221;BooksData&#8221;.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding XPath=@name}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the result of an XPath query run on the XML node in the DataContext (for example in an ItemControl&#8217;s DataTemplate when the ItemsControl.ItemsSource is bound to an XML data source).</td>
</tr>
</tbody>
</table>
</div>
<div>
<table style="border-collapse:collapse;" border="0">
<col span="1"></col>
<col span="1"></col>
<tbody>
<tr style="background:#4f81bd;height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-left:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;" colspan="2"><span style="color:white;"><strong>Relative Source Binding</strong></span></td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding RelativeSource={RelativeSource Self}}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the target element.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding RelativeSource={RelativeSource Self}, Path=Name}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the &#8220;Name&#8221; property of the target element.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">{Binding <strong>RelativeSource={RelativeSource </strong>FindAncestor, AncestorType={<strong>x:Type Window}}, </strong>Path=Title}</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the title of the parent window.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}, AncestorLevel=2}, Path=Name}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind the the name of the 2nd parent of type ItemsControl.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">{Binding <strong>RelativeSource={RelativeSource </strong>TemplatedParent}, Path=Name}</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Inside a control template, bind to the name property of the element the template is applied to. </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{TemplateBinding Name}</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Shortcut for the previous example.</td>
</tr>
</tbody>
</table>
</div>
<div>
<table style="border-collapse:collapse;" border="0">
<col span="1"></col>
<col span="1"></col>
<tbody>
<tr style="background:#4f81bd;height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-left:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;" colspan="2"><span style="color:white;"><strong>Collection Current Item Binding</strong></span></td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding /}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the current item in the DataContext (when DataContext is a collection)</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>{Binding AllItems/}</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the current item in the &#8220;AllItems&#8221; property of the DataContext</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">{Binding AllItems/Name}</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Bind to the &#8220;Name&#8221; property of the current item in the &#8220;AllItems&#8221; property of the DataContext</td>
</tr>
</tbody>
</table>
</div>
<p>Alphabetical list of all Binding&#8217;s properties</p>
<div>
<table style="border-collapse:collapse;" border="0">
<col span="1"></col>
<col span="1"></col>
<tbody>
<tr style="background:#4f81bd;height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><span style="color:white;"><strong>Property</strong></span> </td>
<td style="padding-left:7px;padding-right:7px;border-top:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;"><span style="color:white;">Description</span></td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>BindingGroupName (3.5sp1)</strong></td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">The name of the BindingGroup to which this binding belongs. A BindingGroup is used to validate multiple bindings together (for example when multiple changes should be submitted all at once).</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>BindsDirectlyToSource</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">When using a DataSourceProvider derived class (for example a ObjectDataProvider) setting this property to true will bind to the data source provider object itself, leaving it false will bind to the data contained in the data source.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">Converter</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">The converter to use, usually you create the converter in a parent element&#8217;s Resources element and reference it using a {StaticResource name) or create the converter as a static field and reference it with {x:Static ns:class.field}</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>ConverterCulture</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">The culture passed to the converter.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">ConverterParameter</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">The parameter passed to the converter </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>ElementName</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Element name, when binding to an element in the same XAML scope. Can&#8217;t be used if RelativeSource or Source is set.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">FallbackValue</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Value to use when the Binding encounters an error</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>IsAsync</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Use when the property&#8217;s get accessor takes a long time, to avoid blocking the UI thread, While waiting for the value to arrive, the binding reports the FallbackValue.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">Mode</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Direction of binding, possible options:</p>
<ul>
<li>TwoWay &#8211; updates the target property or the source property whenever the other one changes.</li>
<li>OneWay &#8211; updates the target property only when the source property changes.</li>
<li>OneTime &#8211; updates the target property only when the application starts or when the DataContext undergoes a change.</li>
<li>OneWayToSource &#8211; updates the source property when the target property changes, useful the target property is not a dependency property – put the binding on what would normally be the source and point it to the target.</li>
<li>Default &#8211; causes the default Mode value of target property to be used</li>
</ul>
</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>NotifyOnSourceUpdated</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Raise the SourceUpdated event when a value is transferred from the binding target to the binding source.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">NotifyOnTargetUpdated</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Raise the TargetUpdated event when a value is transferred from the binding source to the binding target.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>NotifyOnValidationError</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Raise the Error attached event on the bound object.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">Path</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Source property. </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>RelativeSource</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Binding source relative to the target, possible options:</p>
<ul>
<li>{x:Static RelativeSource.Self} or {RelativeSource Self} bind to target element.</li>
<li>{RelativeSource FindAncestor, AncestorType={x:Type TypeName}} Bind to the first parent of type TypeName</li>
<li>{RelativeSource FindAncestor, AncestorType={x:Type TypeName}, AnsestorLevel=n} Bind to the nth parent of type TypeName</li>
<li>{RelativeSource TemplatedParent} bind to the element this template is applied to (useful in control templates, considerusing TemplateBinding instead. Can&#8217;t be used if ElementName or Source is set.</li>
</ul>
</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">Source</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Object to use as the binding source. Can&#8217;t be used if ElementName or RelativeSource is set </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>StringFormat (3.5sp1)</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Format string to use when converting the bound value to a string. Works only if the target property is of type string. </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">TargetNullValue (3.5sp1)</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Value to use when the bound value is null.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>UpdateSourceExceptionFilter</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Custom logic for handling exceptions that the binding engine encounters. Only if you add an ExceptionValidationRule to ValidationRules or set ValidatesOnExceptions</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">UpdateSourceTrigger</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">timing of binding source updates, possible options:</p>
<ul>
<li>Default &#8211; The default UpdateSourceTrigger value of the binding target property. The default is usually PropertyChanged, while the Text property is LostFocus.</li>
<li>PropertyChanged &#8211; Updates the binding source immediately whenever the binding target property changes.</li>
<li>LostFocus &#8211; Updates the binding source whenever the binding target element loses focus.</li>
<li>Explicit &#8211; Updates the binding source only when you call the UpdateSource method.</li>
</ul>
</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>ValidatesOnDataErrors (3.5sp1)</strong></td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Use IDataErrorInfo when validating.</td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">ValidatesOnExceptions (3.5sp1)</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Treat exceptions as validation failures. </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;"><strong>ValidationRules</strong> </td>
<td style="padding-left:7px;padding-right:7px;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">Collection of rules that check the validity of the user input. </td>
</tr>
<tr style="height:17px;">
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid #4f81bd 1pt;border-bottom:solid #4f81bd 1pt;">XPath</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-bottom:solid #4f81bd 1pt;border-right:solid #4f81bd 1pt;">XPath query that returns the value on the XML binding source to use. Top</td>
</tr>
</tbody>
</table>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using progress bar inside the List view]]></title>
<link>http://zamjad.wordpress.com/2009/11/22/using-progress-bar-inside-the-tree-view/</link>
<pubDate>Mon, 23 Nov 2009 04:47:37 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/22/using-progress-bar-inside-the-tree-view/</guid>
<description><![CDATA[We can easily insert progras bar inside the tree view just like we added check box and combo box. We]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We can easily insert progras bar inside the tree view just like we added check box and combo box. We are again going to use the CellTemplate property of GridViewColumn. We are going to define data template to use the progress bar. </p>
<p>This time we are going to do something useful rather than using some dummy sample. This time we are going to make one simple application to calculate the book value of a fixed assets cost using the straight line method. </p>
<p>Here is a class to store the information about the depreciation. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> DepreciationInfo
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: 	<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Year
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: 	{ <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: 	<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Depreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: 	{ <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> AccDepreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: 	{ <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 	<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> BookValue
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	{ <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: 	<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Percentage
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: 	{ <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18: </pre>
</pre>
<p>Calculation of book value using straight line method is very simple. Here is a simple method to calculate the book value.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">double</span> depExpense = depValue / year;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">double</span> accDepreciation = 0;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">double</span> bookValue = cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> iIndex = 0; iIndex &#60; year; iIndex++)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: 	accDepreciation += depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: 	bookValue -= depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: 	DepreciationInfo dpInfo = <span style="color:#0000ff;">new</span> DepreciationInfo();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: 	dpInfo.Year = (iIndex + 1);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: 	dpInfo.Depreciation = depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: 	dpInfo.AccDepreciation = accDepreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	dpInfo.BookValue = bookValue;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14: 	dpInfo.Percentage = bookValue * 100 / cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: 	depreciation.Add(dpInfo);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19: </pre>
</pre>
<p>Here is a complete XAML code of this project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;Depreciation.Window1&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:     <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:     <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:     <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;Depreciation&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;400&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;600&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">Background</span>=<span style="color:#0000ff;">&#34;AliceBlue&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;4*&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter Cost of Fixed Asset<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtCost&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter life Span<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtYear&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>Enter Scrap Value<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBox</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtScrapValue&#34;</span><span style="color:#0000ff;">&#62;</span><span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBox</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListView</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;3&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">ColumnSpan</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;list&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">HorizontalContentAlignment</span>=<span style="color:#0000ff;">&#34;Stretch&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ListView.View</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridView.ColumnHeaderTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:                             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Border</span> <span style="color:#ff0000;">BorderBrush</span>=<span style="color:#0000ff;">&#34;Brown&#34;</span> <span style="color:#ff0000;">BorderThickness</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">CornerRadius</span>=<span style="color:#0000ff;">&#34;5&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Border.Background</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:                                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">LinearGradientBrush</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:                                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GradientStop</span> <span style="color:#ff0000;">Offset</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Color</span>=<span style="color:#0000ff;">&#34;Wheat&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:                                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GradientStop</span> <span style="color:#ff0000;">Offset</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Color</span>=<span style="color:#0000ff;">&#34;LightCoral&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:                                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">LinearGradientBrush</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:                                 <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Border.Background</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Foreground</span>=<span style="color:#0000ff;">&#34;Blue&#34;</span> <span style="color:#ff0000;">FontSize</span>=<span style="color:#0000ff;">&#34;14&#34;</span> <span style="color:#ff0000;">FontWeight</span>=<span style="color:#0000ff;">&#34;Bold&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Text</span>=<span style="color:#0000ff;">&#34;{Binding}&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:                             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Border</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:                         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridView.ColumnHeaderTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Year&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=Year}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Depreciation&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=Depreciation}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Accumulated Depreciation&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=AccDepreciation}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Book Value&#34;</span> <span style="color:#ff0000;">DisplayMemberBinding</span>=<span style="color:#0000ff;">&#34;{Binding Path=BookValue}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:                     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;Auto&#34;</span> <span style="color:#ff0000;">Header</span>=<span style="color:#0000ff;">&#34;Percentage&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:                         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">GridViewColumn.CellTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:                             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:                                 <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ProgressBar</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;50&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;20&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Minimum</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Maximum</span>=<span style="color:#0000ff;">&#34;100&#34;</span> <span style="color:#ff0000;">Value</span>=<span style="color:#0000ff;">&#34;{Binding Percentage}&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:                             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:                         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridViewColumn.CellTemplate</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:                     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridViewColumn</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:                 <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">GridView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:             <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListView.View</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ListView</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;10&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;75&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;btnCalculate&#34;</span> <span style="color:#ff0000;">Click</span>=<span style="color:#0000ff;">&#34;btnCalculate_Click&#34;</span><span style="color:#0000ff;">&#62;</span>Calculate<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Button</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;10&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;75&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;btnExit&#34;</span> <span style="color:#ff0000;">Click</span>=<span style="color:#0000ff;">&#34;btnExit_Click&#34;</span><span style="color:#0000ff;">&#62;</span>Exit<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Button</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59: </pre>
</pre>
<p>Here is a complete C# code of this project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">using</span> System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">using</span> System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">using</span> System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">using</span> System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">using</span> System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">using</span> System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">using</span> System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">using</span> System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">using</span> System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">using</span> System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: <span style="color:#0000ff;">using</span> System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: <span style="color:#0000ff;">using</span> System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">using</span> System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: <span style="color:#0000ff;">namespace</span> Depreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:     <span style="color:#808080;">/// &#60;summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:     <span style="color:#808080;">/// Interaction logic for Window1.xaml</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     <span style="color:#808080;">/// &#60;/summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     <span style="color:#0000ff;">public</span> partial <span style="color:#0000ff;">class</span> Window1 : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         List&#60;DepreciationInfo&#62; depreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> year;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">double</span> cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">double</span> scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:         <span style="color:#0000ff;">public</span> Window1()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:             depreciation = <span style="color:#0000ff;">new</span> List&#60;DepreciationInfo&#62;();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> btnExit_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:             Close();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> btnCalculate_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:             depreciation.Clear();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:             year = Convert.ToInt32(txtYear.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:             cost = Convert.ToDouble(txtCost.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:             scrap = Convert.ToDouble(txtScrapValue.Text);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:             <span style="color:#0000ff;">if</span> (year &#60;= 0)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:                 MessageBox.Show(&#34;<span style="color:#8b0000;">Number of years can not be zero or negative.</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:                 <span style="color:#0000ff;">return</span>;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:             <span style="color:#0000ff;">double</span> depValue = cost - scrap;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:             <span style="color:#0000ff;">if</span> (depValue &#60;= 0)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:                 MessageBox.Show(&#34;<span style="color:#8b0000;">Either Cost or Scrap value is not correct.</span>&#34;);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58:                 <span style="color:#0000ff;">return</span>;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 60:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 61:             <span style="color:#0000ff;">double</span> depExpense = depValue / year;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 62:             <span style="color:#0000ff;">double</span> accDepreciation = 0;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 63:             <span style="color:#0000ff;">double</span> bookValue = cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 64:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 65:             <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> iIndex = 0; iIndex &#60; year; iIndex++)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 66:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 67:                 accDepreciation += depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 68:                 bookValue -= depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 69:                 DepreciationInfo dpInfo = <span style="color:#0000ff;">new</span> DepreciationInfo();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 70:                 dpInfo.Year = (iIndex + 1);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 71:                 dpInfo.Depreciation = depExpense;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 72:                 dpInfo.AccDepreciation = accDepreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 73:                 dpInfo.BookValue = bookValue;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 74:                 dpInfo.Percentage = bookValue * 100 / cost;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 75:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 76:                 depreciation.Add(dpInfo);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 77:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 78:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 79:             list.ItemsSource = depreciation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 80:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 81:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 82:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 83:     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> DepreciationInfo
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 84:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 85:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Year
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 86:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 87:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 88:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Depreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 89:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 90:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 91:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> AccDepreciation
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 92:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 93:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 94:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> BookValue
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 95:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 96:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 97:         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Percentage
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 98:         { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 99:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">100: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">101: </pre>
</pre>
<p>Here is the output of this program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/depreciation.gif"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="Depreciation" border="0" alt="Depreciation" src="http://zamjad.files.wordpress.com/2009/11/depreciation_thumb.gif?w=600&#038;h=400" width="600" height="400" /></a></p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
