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

<channel>
	<title>Rohit's Blog &#187; WPF</title>
	<atom:link href="http://www.smart-techie.com/blog/category/computing/coding-programming/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.smart-techie.com/blog</link>
	<description>My opinion about anything and everything!</description>
	<lastBuildDate>Sun, 15 Jan 2012 05:13:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ControlTemplates in XAML</title>
		<link>http://www.smart-techie.com/blog/2006/12/controltemplates-in-xaml/</link>
		<comments>http://www.smart-techie.com/blog/2006/12/controltemplates-in-xaml/#comments</comments>
		<pubDate>Fri, 15 Dec 2006 19:16:46 +0000</pubDate>
		<dc:creator>Rohit</dc:creator>
				<category><![CDATA[Coding/ Programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.smart-techie.com/blog/2006/12/16/23/</guid>
		<description><![CDATA[XAML has this great concept of look-less controls. When we see a normal Win32 control like say a checkbox, we always assume that it will be a square box along with some text written to the left of it. Taking an example from our old friend WordPad, we would always expect a checkbox to look [...]]]></description>
			<content:encoded><![CDATA[<div class="entrytext">
<p>XAML has this <em>great</em> concept of look-less controls. When we see a normal Win32 control like say a checkbox, we always assume that it will be a square box along with some text written to the left of it. Taking an example from our old friend WordPad, we would always expect a checkbox to look like</p>
</div>
<p class="c6"><img src="http://i104.photobucket.com/albums/m190/rohit_sud/picidd5908DsDmfED-6ipuz2GcoaxIcYOOd.jpg" /></p>
<p>
  </p>
<p>Pretty boring, if you would ask a kid (or even a teenager!). Even though it makes the control much more usable (which is a <strong>very</strong> important thing BTW), it doesn&#8217;t look <strong><em>cool</em></strong>. So how does WPF help us here?</p>
<p>For starters, when you define a control, WPF doesn&#8217;t force to you to define the look of the control along with the functionality. Here comes the concept of a look-less control; a control whose behaviour is defined but whose look is not defined. For instance, we might define the behavior of the check box (it has a bool or a bool? property called IsChecked, it has a check mark to the left of the content, etc&#8230<img src='http://www.smart-techie.com/blog/smilies/msn_wink.gif' alt='&#59;&#41;' class='wp-smiley' width='19' height='19' title='&#59;&#41;' /> but leave it to the author to define the look for it. So we might have something like</p>
<div>
<table cellspacing="0" cellpadding="3" width="100%" border="0">
<tbody>
<tr>
<td width="50%">
<p><img src="http://i104.photobucket.com/albums/m190/rohit_sud/picidd5908DsDmfED-6ipuz2GcoaxLJao3I.jpg" align="left" /></p>
</td>
<td width="50%">Checked Checkbox<br />
          </td>
</tr>
<tr>
<td width="50%">
<p><img src="http://i104.photobucket.com/albums/m190/rohit_sud/picidd5908DsDmfED-6ipuz2GcoaxNvsd7G.jpg" align="left" /></p>
</td>
<td width="50%">Unchecked Checkbox</td>
</tr>
</tbody>
</table>
</div>
<p>
  </p>
<p>How to go about doing this? This is all done by redefining the ControlTemplate for the checkbox. ControlTemplate is basically what it says, it is a Template for the Control and decides how the control will <span class="c7">look</span> like. To achieve such a look we define the Style of the Checkbox as</p>
<blockquote>
<pre class="xmlcode"><code><span class="xml01">&lt;Style</span><span class="xml08"> </span><span class="xml03">x:Key</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml08"> </span><span class="xml03">TargetType</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml01">&gt;</span>
    <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;SnapsToDevicePixels&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;true&quot;</span><span class="xml08">/</span><span class="xml01">&gt;</span>
    <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;OverridesDefaultStyle&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;true&quot;</span><span class="xml08">/</span><span class="xml01">&gt;</span>
    <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;Template&quot;</span><span class="xml01">&gt;</span>
      <span class="xml01">&lt;Setter.Value&gt;</span>
        <span class="xml01">&lt;ControlTemplate</span><span class="xml08"> </span><span class="xml03">TargetType</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml01">&gt;</span>
          <span class="xml01">&lt;WrapPanel</span><span class="xml08"> </span><span class="xml03">Orientation</span><span class="xml08">=</span><span class="xml19">&quot;Horizontal&quot;</span><span class="xml01">&gt;</span>
            <span class="xml01">&lt;Border</span><span class="xml08"> </span><span class="xml03">x:Name</span><span class="xml08">=</span><span class="xml19">&quot;Border&quot;</span><span class="xml08">
              </span><span class="xml03">CornerRadius</span><span class="xml08">=</span><span class="xml19">&quot;0</span><span class="xml08">&#8221; </span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Image</span><span class="xml08"> </span><span class="xml03">Name</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml08">
                      </span><span class="xml03">Height</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">Binding</span><span class="xml08"> </span><span class="xml03">ElementName</span><span class="xml08">=</span><span class="xml19">MyContent</span><span class="xml08">, </span><span class="xml03">Path</span><span class="xml08">=</span><span class="xml19">ActualHeight</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml08"> </span><span class="xml03">Source</span><span class="xml08">=</span><span class="xml19">&quot;happy.gif&quot;</span><span class="xml01">&gt;</span>
                <span class="xml01">&lt;Image.BitmapEffect&gt;</span>
                  <span class="xml01">&lt;OuterGlowBitmapEffect</span><span class="xml08"> </span><span class="xml03">GlowColor</span><span class="xml08">=</span><span class="xml19">&quot;Blue&quot;</span><span class="xml08"> </span><span class="xml03">GlowSize</span><span class="xml08">=</span><span class="xml19">&quot;2</span><span class="xml08">&#8221; </span><span class="xml03">Noise</span><span class="xml08">=</span><span class="xml19">&quot;.1</span><span class="xml08">&#8221; </span><span class="xml03">Opacity</span><span class="xml08">=</span><span class="xml19">&quot;0.8</span><span class="xml08">&quot;</span><span class="xml11">/&gt;</span>
                <span class="xml01">&lt;/Image.BitmapEffect&gt;</span>
              <span class="xml01">&lt;/Image&gt;</span>
            <span class="xml01">&lt;/Border&gt;</span>
            <span class="xml01">&lt;ContentPresenter</span><span class="xml08"> </span><span class="xml03">Margin</span><span class="xml08">=</span><span class="xml19">&quot;4</span><span class="xml08">,</span><span class="xml05">0</span><span class="xml08">,</span><span class="xml05">0</span><span class="xml08">,</span><span class="xml05">0</span><span class="xml08">&quot; </span><span class="xml03">Name</span><span class="xml08">=</span><span class="xml19">&quot;MyContent&quot;</span><span class="xml08">
              </span><span class="xml03">VerticalAlignment</span><span class="xml08">=</span><span class="xml19">&quot;Center&quot;</span><span class="xml08">
              </span><span class="xml03">HorizontalAlignment</span><span class="xml08">=</span><span class="xml19">&quot;Left&quot;</span><span class="xml08">
              </span><span class="xml03">RecognizesAccessKey</span><span class="xml08">=</span><span class="xml19">&quot;True&quot;</span><span class="xml08">/</span><span class="xml01">&gt;</span>
          <span class="xml01">&lt;/WrapPanel&gt;</span>
          <span class="xml01">&lt;ControlTemplate.Triggers&gt;</span>
            <span class="xml01">&lt;Trigger</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;IsChecked&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Null</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;Source&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;unsure.gif&quot;</span><span class="xml08"> </span><span class="xml11">/&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;BitmapEffect&quot;</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml01">&gt;</span>
                <span class="xml01">&lt;Setter.Value&gt;</span>
                  <span class="xml01">&lt;OuterGlowBitmapEffect</span><span class="xml08"> </span><span class="xml03">GlowColor</span><span class="xml08">=</span><span class="xml19">&quot;Black&quot;</span><span class="xml08"> </span><span class="xml03">GlowSize</span><span class="xml08">=</span><span class="xml19">&quot;2</span><span class="xml08">&quot; </span><span class="xml03">Noise</span><span class="xml08">=</span><span class="xml19">&quot;.1</span><span class="xml08">&quot;
                  </span><span class="xml03">Opacity</span><span class="xml08">=</span><span class="xml19">&quot;0.8</span><span class="xml08">&quot; </span><span class="xml11">/&gt;</span>
                <span class="xml01">&lt;/Setter.Value&gt;</span>
              <span class="xml01">&lt;/Setter&gt;</span>
            <span class="xml01">&lt;/Trigger&gt;</span>
            <span class="xml01">&lt;Trigger</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;IsChecked&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;false&quot;</span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;Source&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;sad.gif&quot;</span><span class="xml08"> </span><span class="xml11">/&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;BitmapEffect&quot;</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Null</span><span class="xml08">}</span><span class="xml03">&quot;/</span><span class="xml01">&gt;</span>
            <span class="xml01">&lt;/Trigger&gt;</span>
            <span class="xml01">&lt;Trigger</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;IsMouseOver&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;true&quot;</span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;BitmapEffect&quot;</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml01">&gt;</span>
                <span class="xml01">&lt;Setter.Value&gt;</span>
                  <span class="xml01">&lt;OuterGlowBitmapEffect</span><span class="xml08"> </span><span class="xml03">GlowColor</span><span class="xml08">=</span><span class="xml19">&quot;Red&quot;</span><span class="xml08"> </span><span class="xml03">GlowSize</span><span class="xml08">=</span><span class="xml19">&quot;2</span><span class="xml08">&quot; </span><span class="xml03">Noise</span><span class="xml08">=</span><span class="xml19">&quot;.1</span><span class="xml08">&quot;
                  </span><span class="xml03">Opacity</span><span class="xml08">=</span><span class="xml19">&quot;0.8</span><span class="xml08">&quot; </span><span class="xml11">/&gt;</span>
                <span class="xml01">&lt;/Setter.Value&gt;</span>
              <span class="xml01">&lt;/Setter&gt;</span>
            <span class="xml01">&lt;/Trigger&gt;</span>
            <span class="xml01">&lt;Trigger</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;IsPressed&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;true&quot;</span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;BitmapEffect&quot;</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;CheckMark&quot;</span><span class="xml01">&gt;</span>
                <span class="xml01">&lt;Setter.Value&gt;</span>
                  <span class="xml01">&lt;OuterGlowBitmapEffect</span><span class="xml08"> </span><span class="xml03">GlowColor</span><span class="xml08">=</span><span class="xml19">&quot;Yellow&quot;</span><span class="xml08"> </span><span class="xml03">GlowSize</span><span class="xml08">=</span><span class="xml19">&quot;2</span><span class="xml08">&quot; </span><span class="xml03">Noise</span><span class="xml08">=</span><span class="xml19">&quot;.1</span><span class="xml08">&quot;
                  </span><span class="xml03">Opacity</span><span class="xml08">=</span><span class="xml19">&quot;0.8</span><span class="xml08">&quot; </span><span class="xml11">/&gt;</span>
                <span class="xml01">&lt;/Setter.Value&gt;</span>
              <span class="xml01">&lt;/Setter&gt;</span>
            <span class="xml01">&lt;/Trigger&gt;</span>
            <span class="xml01">&lt;Trigger</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;IsEnabled&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;false&quot;</span><span class="xml01">&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;Border&quot;</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;Background&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">StaticResource</span><span class="xml08"> </span><span class="xml03">DisabledBackgroundBrush</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml08"> </span><span class="xml11">/&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">TargetName</span><span class="xml08">=</span><span class="xml19">&quot;Border&quot;</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;BorderBrush&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">StaticResource</span><span class="xml08"> </span><span class="xml03">DisabledBorderBrush</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml08"> </span><span class="xml11">/&gt;</span>
              <span class="xml01">&lt;Setter</span><span class="xml08"> </span><span class="xml03">Property</span><span class="xml08">=</span><span class="xml19">&quot;Foreground&quot;</span><span class="xml08"> </span><span class="xml03">Value</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">StaticResource</span><span class="xml08"> </span><span class="xml03">DisabledForegroundBrush</span><span class="xml08">}</span><span class="xml03">&quot;/</span><span class="xml01">&gt;</span>
            <span class="xml01">&lt;/Trigger&gt;</span>
          <span class="xml01">&lt;/ControlTemplate.Triggers&gt;</span>
        <span class="xml01">&lt;/ControlTemplate&gt;</span>
      <span class="xml01">&lt;/Setter.Value&gt;</span>
    <span class="xml01">&lt;/Setter&gt;</span>
  <span class="xml01">&lt;/Style&gt;</span></code></pre>
</blockquote>
<p>Let&#226;&#8364;&#8482;s dissect this monster to see how it works <img class="wp-smiley" title=":)" height="21" alt=":)" src="http://www.smart-techie.com/blog/smilies/msn_smiley.png" width="21" /></p>
<p>The first line</p>
<blockquote>
<pre class="xmlcode"><code><span class="xml01">&lt;Style</span><span class="xml08"> </span><span class="xml03">x:Key</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml08"> </span><span class="xml03">TargetType</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml01">&gt;</span></code></pre>
</blockquote>
<p><span class="c10"><span class="c9">means that this is a Style being defined for Type CheckBox in the namespace referred to by x which is <span class="c8">http://schemas.microsoft.com/winfx/2006/xaml</span> in my case.</span></span></p>
<p class="c11">Moving on, the core part of the Style is in defining the ControlTemplarte.</p>
<blockquote>
<pre class="xmlcode"> <code><span class="xml01">&lt;ControlTemplate</span><span class="xml08"> </span><span class="xml03">TargetType</span><span class="xml08">=</span><span class="xml19">&quot;</span><span class="xml08">{</span><span class="xml03">x:Type</span><span class="xml08"> </span><span class="xml03">CheckBox</span><span class="xml08">}</span><span class="xml03">&quot;</span><span class="xml01">&gt;</span></code></pre>
</blockquote>
<p>Note that I could have defined the ControlTemplate for the CheckBox using CheckBox.ControlTemplate but have chosen to implement it using a Style as it is quite common to do so.</p>
<p class="c11">It is in this ControlTemplate that I define the <span class="c7">look</span> of the CheckBox. Here I say that it should be a <span class="c12">WrapPanel</span> which should contain a <span class="c12">Border</span> which has an <span class="c12">Image</span> and a <span class="c12">ContentPresenter</span> in it. You can read more about the <span class="c12">ContentPresenter</span> in MSDN, it is just a <span class="c12">UIElement</span> which can contain and display any other object. The <span class="c12">Image</span> has a binding to the Height of the <span class="c12">ContentPresenter</span> so that it resizes automatically to the Height of the content, else you might have a case when you have text with FontSize 36 points but you checkmark is just 10 pixels high. That&#8217;s it! That&#8217;s the definition of our customized CheckBox; could it be any easier?</p>
<p class="c11">I added some Triggers to change the Image in the CheckBox depending on its state. I have added an image when IsChecked is null to account for a Tri State CheckBox. I also added some BitmapEffects for a Glow (just to make it more pretty!)</p>
<p class="c11">Go through the code, it isn&#8217;t very hard to understand or comprehend. Now whenever you wish your CheckBox to use this style, simply use it as</p>
<blockquote>
<pre class="xmlcode"><code><span class="xml01">&lt;CheckBox</span><span class="xml08"> </span><span class="xml03">Margin</span><span class="xml08">=</span><span class="xml19">&quot;8</span><span class="xml08">&#8221; </span><span class="xml03">Style</span><span class="xml08">=</span><span class="xml19">&quot;myCheckBoxStyle&quot;</span><span class="xml01">&gt;</span>
    <span class="xml01">&lt;TextBlock</span><span class="xml08"> </span><span class="xml03">FontSize</span><span class="xml08">=</span><span class="xml19">&quot;20&quot;</span><span class="xml01">&gt;</span>Happy or Sad?<span class="xml01">&lt;/TextBlock&gt;</span>
<span class="xml01">&lt;/CheckBox&gt;</span></code></pre>
</blockquote>
<p>If you find this article useful, do comment and let me know</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://www.smart-techie.com/blog/2006/12/controltemplates-in-xaml/"><img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.smart-techie.com/blog/2006/12/controltemplates-in-xaml/" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-techie.com/blog/2006/12/controltemplates-in-xaml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Random thoughts == System.Random(object thought)</title>
		<link>http://www.smart-techie.com/blog/2006/09/random-thoughts-systemrandomobject-thought/</link>
		<comments>http://www.smart-techie.com/blog/2006/09/random-thoughts-systemrandomobject-thought/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 19:30:03 +0000</pubDate>
		<dc:creator>Rohit</dc:creator>
				<category><![CDATA[Coding/ Programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.smart-techie.com/blog/2006/09/general/random-thoughts-systemrandomobject-thought/</guid>
		<description><![CDATA[This is the state of my mind at this precise moment. Thinking of code as well as trying to think of something else. Its Friday night, I&#8217;ve had my dinner and am really tired to do any more work. Thought of updating my blog, as it has been weeks since I last did it. Just [...]]]></description>
			<content:encoded><![CDATA[<p>This is the state of my mind at this precise moment. Thinking of code as well as trying to think of something else. Its Friday night, I&#8217;ve had my dinner and am really tired to do any more work. Thought of updating my blog, as it has been weeks since I last did it. Just when I had thought I was going to be working on Java at Trilogy, I changed my plans for no <em>apparent</em> reason and came to Microsoft. Here one, obviously, won&#8217;t work on Java. But imagine my luck, I got to work on its cousin or should I say successor (as Microsoft would like to see it IMHO; I don&#8217;t express any opinions about and of the company, this is a personal blog). This is really cool, I mean working in a familiar domain, with System.Console.println replaced by System.Console.WriteLine most of the things are same. What is not same is the GUI features provided by WinFX or Avalon framework. They are really cool, I mean we can use markup to generate complete UIs which are absolutely STUNNING. In Java or even VC++, I would have to spend hours to write the code, but thanks to the combination of C# and XAML, its a piece of cake to do so.</p>
<p>&nbsp;</p>
<p>&nbsp;<a href='http://www.smart-techie.com/blog/wp-content/uploads/2007/05/winfx.png' title='WinFX' rel="lightbox"><img src='http://www.smart-techie.com/blog/wp-content/uploads/2007/05/winfx.thumbnail.png' alt='WinFX' />WinFX / Avalon</a> </p>
<p>&nbsp;</p>
<p><u><strong>XAML, the new tool (pronounced <em>zammel)</em></strong></u> XAML is an XML based system to create GUIs. BUt it can do much more than that. It provides for cool concepts like data binding. This is something like an element will automatically update its properties based on the properties of another element. So you can have the color of text in a TextBox to be the same as the Background of the Button which is an image. It as simple as writing a markup without any lines of code in C#. The power of XAML is truly phenomenal! <strong>Code: </strong></p>
<blockquote><p><code><span style="color: #0000ff">&lt;</span><span style="color: #800000">Page </span><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><span style="color: #ff0000"> xmlns: sys</span><span style="color: #0000ff">="clr-namespace: System;assembly=mscorlib"</span><span style="color: #ff0000"><br />
 xmlns: x</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Page</span><span style="color: #ff0000">.Resources</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">ImageBrush </span><span style="color: #ff0000">x:Key</span><span style="color: #0000ff">="SomeImage"</span><span style="color: #ff0000"> ImageSource</span><span style="color: #0000ff">="C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg"</span><span style="color: #0000ff">/&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Page.Resources</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">StackPanel </span><span style="color: #ff0000">Height</span><span style="color: #0000ff">="150"</span><span style="color: #ff0000"> Width</span><span style="color: #0000ff">="350"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Button </span><span style="color: #ff0000">Background</span><span style="color: #0000ff">="{StaticResource SomeImage}"</span><span style="color: #ff0000"> Name</span><span style="color: #0000ff">="button"</span><span style="color: #ff0000"> Height</span><span style="color: #0000ff">="60"</span><span style="color: #0000ff">/&gt;</span><span style="color: #000000"><br />
      </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBox </span><span style="color: #ff0000">Foreground</span><span style="color: #0000ff">="{Binding Path=Background, ElementName=button}"</span><span style="color: #ff0000"> FontSize</span><span style="color: #0000ff">="20"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
        Some Text with a picture background<br />
    </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">TextBox</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Page</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"></p>
<p></span><br />
</code>
</p></blockquote>
<p>And the result! </p>
<p><img alt="XAML screenshot" src="http://i104.photobucket.com/albums/m190/rohit_sud/xaml.jpg" border="0" /> Isn&#8217;t this great? Just a few lines of code was needed to produce such an application!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-techie.com/blog/2006/09/random-thoughts-systemrandomobject-thought/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

