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

<channel>
	<title>Veracity Solutions Blog &#187; XAML</title>
	<atom:link href="http://blogs.veracitysolutions.com/category/xaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.veracitysolutions.com</link>
	<description>Software Consulting That Rocks</description>
	<lastBuildDate>Thu, 22 Apr 2010 17:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Create a PART in Your Silverlight Custom Control</title>
		<link>http://blogs.veracitysolutions.com/how-to-create-a-part-in-your-silverlight-custom-control/</link>
		<comments>http://blogs.veracitysolutions.com/how-to-create-a-part-in-your-silverlight-custom-control/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 16:06:22 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[Custom Controls]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Custom Control]]></category>
		<category><![CDATA[PART]]></category>

		<guid isPermaLink="false">http://blogs.veracitysolutions.com/?p=656</guid>
		<description><![CDATA[There are about a dozen videos and tutorials on how to create a custom control in Silverlight 3. (Here’s my favorite, from Karen Corby. Skip to about 47 minutes for the tutorial part.)
But sometimes, you (and by “you”, I mean me) need help figuring out how to create a PART for a control because, let’s [...]]]></description>
			<content:encoded><![CDATA[<p>There are about a dozen videos and tutorials on how to create a custom control in Silverlight 3. (<a href="http://scorbs.com/2009/03/23/mix-09-building-microsoft-silverlight-controls/">Here’s my favorite, from Karen Corby</a>. Skip to about 47 minutes for the tutorial part.)</p>
<p>But sometimes, you (and by “you”, I mean me) need help figuring out how to create a PART for a control because, let’s be honest, you don’t do it all the time and no one has a blog post on just this little part of control building.</p>
<p>If you’re wondering what a PART is, here’s a short explanation: A PART is a naming convention that allows a control (code) to make a contract with the control template (XAML) in Silverlight. The control says to the template, “I’m going to be doing something programmatic with this part, so it better be there”. The template responds, “Here’s that part you wanted.”</p>
<p>I not actually talking down to anyone, this is really how my brain works. </p>
<p>There are basically five steps in creating a PART. I think you can actually do it in less, but I’m trying to follow what I think is proper coding practice. In this tutorial, we’re going create parts out of a Button and also a Storyboard (partly because there are different ways to assign a PART if it is in located in the control resources like a Storyboard is).</p>
<p><b>Step 1: Define the control template parts you’ll need</b></p>
<p>Outside of the control class we need to add the TemplatePart attributes. Inside the class, we need to define the names of the UI objects we’re going to turn into parts as well as create some corresponding objects in the control so we can access those PARTs.</p>
<p>[<span style="color: #2b91af">TemplatePart</span>(Name = <span style="color: #2b91af">MyControl</span>.StoryboardString, Type = <span style="color: blue">typeof</span>(<span style="color: #2b91af">Storyboard</span>))]    <br />[<span style="color: #2b91af">TemplatePart</span>(Name = <span style="color: #2b91af">MyControl</span>.RootElementString, Type = <span style="color: blue">typeof</span>(<span style="color: #2b91af">FrameworkElement</span>))]    <br />[<span style="color: #2b91af">TemplatePart</span>(Name = <span style="color: #2b91af">MyControl</span>.ButtonString, Type = <span style="color: blue">typeof</span>(<span style="color: #2b91af">Button</span>))]    </p>
<p><span style="color: blue">public class </span><span style="color: #2b91af">MyControl </span>: <span style="color: #2b91af">Control     <br /></span>{    <br />&#160;&#160;&#160; <span style="color: blue">private const string </span>StoryboardString = <span style="color: #a31515">&quot;PART_MyStoryboard&quot;</span>;    <br />&#160;&#160;&#160; <span style="color: blue">private const string </span>RootElementString = <span style="color: #a31515">&quot;PART_RootElement&quot;</span>;&#160; <br />&#160;&#160;&#160; <span style="color: blue">private const string </span>ButtonString = <span style="color: #a31515">&quot;PART_MyButton&quot;</span>;</p>
<p>&#160;&#160;&#160; <span style="color: blue">private </span><span style="color: #2b91af">Storyboard </span>_targetStoryboard;    <br /><span style="color: blue">&#160;&#160;&#160; private </span><span style="color: #2b91af">FrameworkElement </span>_rootElement;    <br /><span style="color: blue">&#160;&#160;&#160; private </span><span style="color: #2b91af">Button </span>_targetButton;<a href="http://11011.net/software/vspaste"></a></p>
<p>What we’re going to do here is remarkably stupid because I don’t have the creativity right now to do something cool. When we press the button, we’ll play the storyboard. We need the RootElement because… you’ll see in a moment. </p>
<p><b>Step 2: Make sure you have a XAML template properly named to correspond with the part</b></p>
<p>We have three parts we’re getting here, so this is a stripped down template that just has the three PARTs named appropriately. If the names are not the same as the strings above, it will not work.</p>
<p><span style="color: blue">&lt;</span><span style="color: #a31515">Style</span><span style="color: red">TargetType</span><span style="color: blue">=&quot;local:MyControl&quot;&gt;     <br />&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Setter</span><span style="color: red">Property</span><span style="color: blue">=&quot;Template&quot;&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;local:MyControl&quot;&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;PART_RootElement&quot;&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Grid.Resources</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Storyboard </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;PART_MyStoryboard&quot;&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: green">&lt;!&#8211; Whatever animations you want here &#8211;&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Storyboard</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Grid.Resources</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Button </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;PART_MyButton&quot; /&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">&gt;     <br />&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Setter</span><span style="color: blue">&gt;     <br />&lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;</span></p>
<p> <a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a>
<p><b>Step 3: Assign the XAML PART to the code PART in the OnApplyTemplate method</b></p>
<p>Now we just have to write a custom OnApplyTemplate method that will grab the XAML elements and assign them to objejcts within the control code. There are two key methods you’ll use. The first is GetTemplateChild, which will pull out any UI element in the XAML that is named and not in the resources. </p>
<p>If you want to get something in the resources, you need to refer to the UI element that holds those resources. This is why we needed the root element as a PART. So, enough of my blabbing… here’s the code:</p>
<p><span style="color: blue">public override void </span>OnApplyTemplate()    <br />{    <br />&#160;&#160;&#160; <span style="color: blue">base</span>.OnApplyTemplate();    </p>
<p>&#160;&#160;&#160; _rootElement = GetTemplateChild(<span style="color: #2b91af">MyControl</span>.RootElementString) <span style="color: blue">as </span><span style="color: #2b91af">FrameworkElement</span>;    <br />&#160;&#160;&#160; <span style="color: green">//Make sure we actually got the template applied.     <br />&#160;&#160;&#160; </span><span style="color: blue">if </span>(_rootElement != <span style="color: blue">null</span>)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _targetStoryboard = _rootElement.Resources[<span style="color: #2b91af">MyControl</span>.StoryboardString] <span style="color: blue">as </span><span style="color: #2b91af">Storyboard</span>;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _targetButton = GetTemplateChild(<span style="color: #2b91af">MyControl</span>.ButtonString) <span style="color: blue">as </span><span style="color: #2b91af">Button</span>;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; _targetButton.Click +=<span style="color: blue">new </span><span style="color: #2b91af">RoutedEventHandler</span>(_targetButton_Click);&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>&#160;&#160;&#160; }    <br />}</p>
<p> <a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a>
<p>Now we have all the PARTs assigned so we can do something like adding an event handler to the Button so that, when it is clicked, it runs the storyboard.</p>
<p><span style="color: blue">void&#160; </span>_targetButton_Click(<span style="color: blue">object</span>sender, <span style="color: #2b91af">RoutedEventArgs </span>e)    <br />{    <br />&#160;&#160;&#160;&#160; _targetStoryboard.Begin();    <br />}</p>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>And that’s how you add a PART… both in the regular XAML template and in the resources of the template.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-to-create-a-part-in-your-silverlight-custom-control/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adobe Illustrator To XAML Conversion Options</title>
		<link>http://blogs.veracitysolutions.com/adobe-illustrator-to-xaml-conversion-options/</link>
		<comments>http://blogs.veracitysolutions.com/adobe-illustrator-to-xaml-conversion-options/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 18:53:06 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Adobe Illustrator]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[Mike Swanson]]></category>
		<category><![CDATA[Path]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://blogs.veracitysolutions.com/?p=642</guid>
		<description><![CDATA[One of the things that I’ve been doing as I was working on my Florida Crime Rate data visualization was finding vector maps of the US and converting them into XAML. Pretty much everything I found that was free was in SVG format, so I would pull that into Adobe Illustrator and then export into [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that I’ve been doing as I was working on my <a href="http://blogs.veracitysolutions.com/florida-crime-rates-an-information-visualization-in-silverlight/">Florida Crime Rate data visualization</a> was finding vector maps of the US and converting them into XAML. Pretty much everything I found that was free was in SVG format, so I would pull that into Adobe Illustrator and then export into XAML using <a href="http://www.mikeswanson.com/xamlexport/">Mike Swanson’s really awesome Adobe Illustrator to XAML export plug-in</a>. But I wanted to take a moment and say why I’m still using this plug-in instead of the default Expression Blend Import for Illustrator.</p>
<p>As a case study, let’s look at an SVG file of the US counties. (You can find <a href="http://commons.wikimedia.org/wiki/File:USA_Counties_with_names.svg">a link to the SVG here</a>. Here is <a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/USA_Counties_with_names_AI_Export.xaml">the file converted to XAML</a> if you just want to download that and not mess with any of this other stuff. Special thanks to Nathan Yau of Flowing Data and @SimonRegenbogen for helping me find this.)</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0015.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="clip_image001[5]" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0015_thumb.png" width="565" height="360" /></a></p>
<p>The SVG is about 1.6 MB, but when I convert it to XAML, it sees a size reduction of about 20-25%.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image001.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image001_thumb.png" width="392" height="92" /></a></p>
<p>You’ll notice that the Adobe Illustrator-to-XAML export is about 100 KB smaller than the Expression Blend Illustrator Import. What’s the difference?</p>
<ol>
<li><b>AI-to-XAML preserves path layers and grouping</b> – In the native import version, all the paths are imported into a single Canvas. This makes it really hard to isolate paths and work with them individually. The AI export version groups into separate Canvases so that each state is it’s own canvas. Very handy.</li>
<li><b>AI-to-XAML preserves some metadata</b> – all the paths in the AI-to-XAML version have a comment preceding the path that contains some (not all) of the naming metadata from the SVG file.</li>
<li><b>AI-to-XAML spaces code out better</b> – Here is a sample of the data from the AI-to-XAML version:</li>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0019.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="clip_image001[9]" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0019_thumb.png" width="350" height="120" /></a>      <br />And here is the same path in the native import.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0017.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="clip_image001[7]" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image0017_thumb.png" width="383" height="53" /></a></p>
<p>You’ll notice three things: the first is the metadata (already noted). The second is that the export plug-in has spaced the paths to make them easier to read. The third is something you’ll notice if you’ve spent a lot of time working with XAML paths… the point data is spaced out in a way that makes it much more readable.&#160; Overall a much better XAML experience. </p>
<li><b>AI-to-XAML maintains less path data fidelity</b> – The AI-to-XAML converts to 3 decimal places, while the native import converts to 4 decimal places. But this isn’t necessarily a bad thing. Here is a corner of Sacramento County zoomed in 6400%.</li>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image00111.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="clip_image001[11]" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image00111_thumb.png" width="144" height="90" /></a></p>
<p>Now let’s change the path data by a hundredth of a unit, from X=35.366 to X=35.376</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image00115.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="clip_image001[15]" src="http://www.designersilverlight.com/wp-content/uploads/2009/09/clip_image00115_thumb.png" width="145" height="75" /></a></p>
<p>The difference is almost imperceptible… even at this level of magnification. Changing it by a thousandth of a unit is going to make almost no difference that users will be able to see.</p>
</ol>
<p><b>Conclusion:</b> I’m going to continue using Mike Swanson’s Adobe Illustrator to XAML Export plug-in because it is awesome. If you don’t have or can’t afford Adobe Illustrator, the default import isn’t bad, but it is missing a good deal of potentially valuable functionality.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/adobe-illustrator-to-xaml-conversion-options/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Anchored Layout in Silverlight</title>
		<link>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/</link>
		<comments>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 13:45:06 +0000</pubDate>
		<dc:creator>Gregg Jensen</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[absolute]]></category>
		<category><![CDATA[anchored]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[Sliverlight]]></category>

		<guid isPermaLink="false">http://blogs.veracitysolutions.com/?p=484</guid>
		<description><![CDATA[When I started using Silverlight, I was moving over from Flex, and the first thing I noticed was: Where is my anchored positioning?  
In some cases using a table (Grid) for a layout is not ideal, and if your moving over from Flex like I did, you may want to have something you&#8217;re familiar [...]]]></description>
			<content:encoded><![CDATA[<p>When I started using Silverlight, I was moving over from Flex, and the first thing I noticed was: Where is my anchored positioning?  </p>
<p>In some cases using a table (Grid) for a layout is not ideal, and if your moving over from Flex like I did, you may want to have something you&#8217;re familiar with.  This post walks though how to simulate anchored layout in Sliverlight, using a single cell and applying alignment and margin properties to its elements.</p>
<p>The following example, built in Silverlight, illustrates the types of anchored positioning:</p>
<table>
<tr>
<td>
<div id="attachment_491" class="wp-caption alignleft" style="width: 310px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutnormal.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutnormal.png" alt="Example screen normal size" width="300" height="261" class="size-medium wp-image-491" /></a><p class="wp-caption-text">Example screen normal size</p></div>
</td>
<td>
<div id="attachment_492" class="wp-caption alignleft" style="width: 310px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutstretched.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutstretched.png" alt="Example screen stretched" width="300" height="185" class="size-medium wp-image-492" /></a><p class="wp-caption-text">Example screen stretched</p></div>
</td>
</tr>
</table>
<p>Here is the XAML for the layout of the screen above.</p>
<div id="attachment_502" class="wp-caption aligncenter" style="width: 510px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_xaml.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_xaml.png" alt="XAML for screen" width="500" height="500" class="size-full wp-image-502" /></a><p class="wp-caption-text">XAML for screen</p></div>
<h3>One Cell, Many Possibilities</h3>
</p>
<p>As you can see from the screenshots above, as the page is stretched, the elements stretch and retain their positions also.  Normally this type of layout in Silverlight would require a Grid with 3 columns and 3 rows, and you would have to add the definitions for them as well as set the column and row properties for each element inside the Grid.  To simplify how the page is layed out, only a single cell is needed, and instead the HorizonalAlignment, VerticalAlignment, and Margins are adjusted.  A nice side effect of this type of layout, is the XAML used is significantly reduced.  I&#8217;ll go through each element in turn and explain how it&#8217;s layout is simulated from Flex.  On the left side of each explanation is the constraints as would be defined in Flex.</p>
<h3>Header</h3>
<table>
<tr>
<td>
<div id="attachment_487" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_header.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_header.png" alt="Flex layout constraints for Header" width="200" height="160" class="size-full wp-image-487" /></a><p class="wp-caption-text">Flex layout constraints for Header</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td valign="top">
<br />
<font size="2"><br />
The header of the page stays at the top and stretches left and right.  In Flex a top, left, and right position for the Header would have been set.  In Silverlight, the header of the page is anchored to the top using a VerticalAlignment of Top, and then stretches both left and right by using a HorizontalAlignment of Stretch.  A fixed Height is set, and a left Margin of 100 is applied.<br />
</font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Red&#8221; Height=&#8221;50&#8243; VerticalAlignment=&#8221;Top&#8221; HorizontalAlignment=&#8221;Stretch&#8221; Margin=&#8221;100,0,0,0&#8243;&gt;<br />
			&lt;TextBlock Text=&#8221;Header&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Navigation</h3>
<table>
<tr>
<td>
<div id="attachment_488" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_navigation.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_navigation.png" alt="Flex layout constraints for Navigation" width="200" height="160" class="size-medium wp-image-488" /></a><p class="wp-caption-text">Flex layout constraints for Navigation</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The navigation pane on the page stays vertically centered on the left.  In Flex, the verticalCenter and left positions would be set for the Navigation.  In Silverlight, VerticalAlignment is set to Stretch, and HorizontalAlignment is set to Left, with a fixed Height applied to the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Green&#8221; Width=&#8221;80&#8243; Height=&#8221;200&#8243; VerticalAlignment=&#8221;Stretch&#8221; HorizontalAlignment=&#8221;Left&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Navigation&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Body</h3>
<table>
<tr>
<td>
<div id="attachment_486" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_body.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_body.png" alt="Body layout constraints in Flex" width="200" height="160" class="size-full wp-image-486" /></a><p class="wp-caption-text">Body layout constraints in Flex</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The body of the page stretches in all directions while still leaving room for the other elements.  In Flex, top, left, right, and bottom positions would be set.  In Silverlight, a VerticalAlignment and HorizontalAlignment of Stretch is set, as well as Margins on all sides.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Orange&#8221; VerticalAlignment=&#8221;Stretch&#8221; HorizontalAlignment=&#8221;Stretch&#8221; Margin=&#8221;100,80,80,80&#8243;&gt;<br />
			&lt;TextBlock Text=&#8221;Body&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Buttons</h3>
<table>
<tr>
<td>
<div id="attachment_489" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_buttons.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_buttons.png" alt="Flex layout constraints for Buttons" width="200" height="160" class="size-medium wp-image-489" /></a><p class="wp-caption-text">Flex layout constraints for Buttons</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The buttons on the page are centered horizontally on the bottom.  In Flex, the positions of bottom and right would be set.  In Silverlight, VerticalAlignment is set to Bottom, and HorizonalAlignment is set to Center with a fixed Width and Height on the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Blue&#8221; Width=&#8221;200&#8243; Height=&#8221;60&#8243; VerticalAlignment=&#8221;Bottom&#8221; HorizontalAlignment=&#8221;Stretch&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Buttons&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Page</h3>
<table>
<tr>
<td>
<div id="attachment_490" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_page.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_page.png" alt="Flex layout constraints for Page" width="200" height="160" class="size-medium wp-image-490" /></a><p class="wp-caption-text">Flex layout constraints for Page</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The page number is in the bottom right of the page.  In Flex, a position on the bottom and right would be set.  In Silverlight, VerticalAlignment is set to Bottom, and HorizontalAlignment is set to Right, with a fixed Width and Height applied to the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Purple&#8221; Width=&#8221;80&#8243; Height=&#8221;60&#8243; VerticalAlignment=&#8221;Bottom&#8221; HorizontalAlignment=&#8221;Right&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Page&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Summary</h3>
</p>
<p>The use of the Grid layout can be simplified and simulate Flex anchored layout by only using a single cell, and applying alignments with margins.  Standard absolution positioning can also be achieved within a single cell grid by applying a VerticalAlignment of Top, a HorizontalAlignment of Left, and then using left and top margins for x and y respectively.  The translation from Flex anchored layout to Silverlight can be summarized by the table below:</p>
<table border="1">
<thead>
<tr>
<th>
<h4>&nbsp;Description&nbsp;</h4>
</th>
<th>
<h4>&nbsp;Flex&nbsp;</h4>
</th>
<th>
<h4>&nbsp;Silverlight&nbsp;</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Top left position
</td>
<td>
top, left
</td>
<td>
VerticalAlignment=Top, HorizontalAlignment=Left
</td>
</tr>
<tr>
<td>
Bottom right position
</td>
<td>
bottom, right
</td>
<td>
VerticalAlignment=Bottom, HorizontalAlignment=Right
</td>
</tr>
<tr>
<td>
Center horizontally
</td>
<td>
center
</td>
<td>
HorizontalAlignment=Center
</td>
</tr>
<tr>
<td>
Center vertically
</td>
<td>
verticalCenter
</td>
<td>
VerticalAlignment=Center
</td>
</tr>
<tr>
<td>
Stretch horizontally
</td>
<td>
left, right
</td>
<td>
HorizontalAlignment=Stretch
</td>
</tr>
<tr>
<td>
Stretch vertically
</td>
<td>
top, bottom
</td>
<td>
VerticalAlignment=Stretch
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Styling a Silverlight ScrollViewer (to Look Like a Mac ScrollViewer)</title>
		<link>http://blogs.veracitysolutions.com/styling-a-silverlight-scrollviewer-to-look-like-a-mac-scrollviewer/</link>
		<comments>http://blogs.veracitysolutions.com/styling-a-silverlight-scrollviewer-to-look-like-a-mac-scrollviewer/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 04:04:47 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[ScrollViewer]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Styles]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/08/26/styling-a-silverlight-scrollviewer-to-look-like-a-mac-scrollviewer/</guid>
		<description><![CDATA[Update: Project files for the Silverlight Mac ScrollViewer have been uploaded.
 Just because we&#8217;re working in Microsoft technologies doesn&#8217;t mean we can&#8217;t throw a bone to our Mac friends. After all, they are the people we love, our cousins and our neighbors, and that irritating guy who is dating our daughter and can&#8217;t seem to shut up [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> Project files for the <a href="http://www.designerwpf.com/wp-content/uploads/2008/09/macscrollviewer.zip" title="Silverlight Mac ScrollViewer">Silverlight Mac ScrollViewer have been uploaded</a>.</p>
<p> Just because we&#8217;re working in Microsoft technologies doesn&#8217;t mean we can&#8217;t throw a bone to our Mac friends. After all, they are the people we love, our cousins and our neighbors, and that irritating guy who is dating our daughter and can&#8217;t seem to shut up about how awesome his Mac is even though he&#8217;ll be long out of his program in musical costume design before he ever pays off his laptop &#8230;</p>
<p>Issues? I don&#8217;t have issues. Why do you ask?</p>
<p>Anyway, since Silverlight is a semi-ubiquitous technology, it would be nice if we could cater to all platforms and not make anyone feel left out. And nothing makes people feel more left out than when they expect their application to work one way and it doesn&#8217;t.</p>
<p>So, here&#8217;s a picture of what we&#8217;re going for.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0012.png"><img border="0" width="181" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001-thumb1.png" alt="clip_image001" height="156" style="border: 0px" /></a></p>
<p>As far as I&#8217;m concerned (and therefore as far as this tutorial is concerned) the important stuff is to make sure that the incremental buttons (the arrow buttons in the bottom right) are in the right place. We can deal with the color later.</p>
<p>OK, so let create our ScrollViewer (I&#8217;ll be using Blend exclusively for this). I tossed a button in it and made it small so we can see both of the ScrollBars.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0014.png"><img border="0" width="213" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0014-thumb.png" alt="clip_image001[4]" height="160" style="border: 0px" /></a></p>
<p>Right click on the ScrollViewer in the &#8220;Objects and Timeline&#8221; section and go down to &#8220;Edit Control Parts (Template) -&gt; Edit a Copy&#8230;&#8221;</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0016.png"><img border="0" width="330" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0016-thumb.png" alt="clip_image001[6]" height="101" style="border: 0px" /></a></p>
<p>You should have something that looks like this:</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0018.png"><img border="0" width="249" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0018-thumb.png" alt="clip_image001[8]" height="149" style="border: 0px" /></a></p>
<p>Let&#8217;s do the VerticalScrollBar first. Right click on it and go to &#8220;Edit Control Parts (Template) -&gt; Edit a Copy&#8230;&#8221; Name it something memorable and you should get something like this:</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001121.png"><img border="0" width="254" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00112-thumb1.png" alt="clip_image001[12]" height="252" style="border: 0px" /></a></p>
<p>This is actually easier than it looks. The unnamed rectangles and the path lay down the basic visual backbone for the ScrollBar and the rest of it runs like this:<br />
<a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001141.png"><img border="0" width="45" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00114-thumb1.png" alt="clip_image001[14]" height="37" style="border: 0px" /></a><br />
VerticalSmallDecrease &#8211; The up button<br />
VerticalLargeDecrease &#8211; The space between the up button and the VerticalThumb<br />
<a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00116.png"><img border="0" width="45" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00116-thumb1.png" alt="clip_image001[16]" height="104" style="border: 0px" /></a><br />
VerticalThumb &#8211; The interface element that allows the dragging interaction of the scrollbar<br />
VerticalLargeIncrease &#8211; The space between the down button and the VerticalThumb<br />
<a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001181.png"><img border="0" width="46" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00118-thumb1.png" alt="clip_image001[18]" height="30" style="border: 0px" /></a><br />
VerticalSmallIncrease &#8211; The down button</p>
<p>The horizontal root in this template is strikingly similar.</p>
<p>So, let&#8217;s start by moving the VerticalSmallDecrease button down to the bottom above the VerticalSmallIncrease button. The magic here will happen in the VerticalRoot grid. (I highly recommend the Design/XAML split view for this one.) In the design view, our grid looks like this:</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001201.png"><img border="0" width="103" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00120-thumb1.png" alt="clip_image001[20]" height="277" style="border: 0px" /></a></p>
<p>Ugly. However, in the XAML, it looks like this:</p>
<p><span style="color: blue">&lt;</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;<br />
      &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&#8221;Auto&#8221;/&gt;<br />
</span>      <span style="color: blue">&lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&#8221;Auto&#8221;/&gt;<br />
      &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&#8221;Auto&#8221;/&gt;<br />
      &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&#8221;*&#8221;/&gt;<br />
      &lt;</span><span style="color: #a31515">RowDefinition </span><span style="color: red">Height</span><span style="color: blue">=&#8221;Auto&#8221;/&gt;<br />
&lt;/</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;<br />
&lt;</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;<br />
      &lt;</span><span style="color: #a31515">ColumnDefinition</span><span style="color: blue">/&gt;<br />
      &lt;</span><span style="color: #a31515">ColumnDefinition</span><span style="color: blue">/&gt;<br />
&lt;/</span><span style="color: #a31515">Grid.ColumnDefinitions</span><span style="color: blue">&gt;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Much easier. For the purposes of maintaining a coherent structure, drag the VerticalSmallDecrease in Objects and Timeline pane until it is between the VerticalSmallIncrease and the VerticalLargeIncrease. Next, change the third RowDefinition to &#8220;*&#8221;. You can do this in the XAML or by clicking on the &#8220;Auto&#8221; icon<a href="http://www.designerwpf.com/wp-content/uploads/2008/08/image.png"><img border="0" width="19" src="http://www.designerwpf.com/wp-content/uploads/2008/08/image-thumb.png" alt="image" height="18" style="border: 0px" /></a> until it becomes a &#8220;*&#8221; icon. <a href="http://www.designerwpf.com/wp-content/uploads/2008/08/image1.png"><img border="0" width="22" src="http://www.designerwpf.com/wp-content/uploads/2008/08/image-thumb1.png" alt="image" height="19" style="border: 0px" /></a> Change the fourth RowDefinition from &#8220;*&#8221; to &#8220;Auto&#8221;. When you do this, it won&#8217;t immediately act like an &#8220;Auto&#8221;. This is because Blend gives it an automatic &#8220;MinHeight&#8221; of whatever the current Height is. You can change that in the XAML (easiest move) or you can highlight that row by clicking just below the &#8220;Auto&#8221; icon until the row highlights in a semitransparent gray like so.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001281.png"><img border="0" width="90" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00128-thumb1.png" alt="clip_image001[28]" height="82" style="border: 0px" /></a></p>
<p>You may need to zoom in to do this. Once highlighted, the properties of the Row will show up in the Properties tab on the right. Change the MinHeight to 0.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00132.png"><img border="0" width="286" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00132-thumb.png" alt="clip_image001[32]" height="128" style="border: 0px" /></a></p>
<p>Now we&#8217;ll need to change the Grid.Row properties of almost everything. Click on the items in the Objects and Timeline and change the Row property in the Layout section of the Properties tab like so:</p>
<p>VerticalLargeDecrease -&gt; Row = 0<br />
VerticalThumb -&gt; Row = 1<br />
VerticalLargeIncrease -&gt; Row = 2<br />
VerticalSmallDecrease -&gt; Row = 3<br />
VerticalSmallIncrease -&gt; Row = 4</p>
<p>You&#8217;re done. With the Vertical part of the ScrollBar at least. You can do the same thing with the Horizontal part of it. Just move around the buttons, change the ColumnDefinitions and update the Column assignments. My best recommendation is to go back to the ScrollViewer template and assign your new ScrollBar template to the HorizontalScrollBar and then go back to editing the template from there.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00134.png"><img border="0" width="447" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00134-thumb.png" alt="clip_image001[34]" height="118" style="border: 0px" /></a></p>
<h2>Later on&#8230;</h2>
<p>After a bunch of color tweaking, I have a scroll viewer in silverlight that looks like this:</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00136.png"><img border="0" width="44" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00136-thumb.png" alt="clip_image001[36]" height="246" style="border: 0px" /></a></p>
<p>I&#8217;m feeling OK with it. I&#8217;ve embedded what I have at this point below.</p>
<p><iframe scrolling="no" frameBorder="0" src="http://silverlight.services.live.com/invoke/77530/MacScrollViewer/iframe.html" style="width: 400px; height: 300px"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/styling-a-silverlight-scrollviewer-to-look-like-a-mac-scrollviewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip For Finding Resources for a Control in generic.xaml</title>
		<link>http://blogs.veracitysolutions.com/tip-for-finding-resources-for-a-control-in-genericxaml/</link>
		<comments>http://blogs.veracitysolutions.com/tip-for-finding-resources-for-a-control-in-genericxaml/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 00:39:42 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/08/26/tip-for-finding-resources-for-a-control-in-genericxaml/</guid>
		<description><![CDATA[I&#8217;ve recently be working on changing the ControlTemplate of a GridViewColumnHeader in a custom ListView that we&#8217;ve been working on. (The ListView was rewritten for sorting, so that&#8217;s why it had to be custom.)
One of the things we had to do was swap out ControlTemplates so that we could display a caret to indicate ascending [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently be working on changing the ControlTemplate of a GridViewColumnHeader in a custom ListView that we&#8217;ve been working on. (The ListView was rewritten for sorting, so that&#8217;s why it had to be custom.)</p>
<p>One of the things we had to do was swap out ControlTemplates so that we could display a caret to indicate ascending or descending lists. We ended up deciding on ControlTemplates over DataTemplates because the DataTemplates would only work for ListViews that had no custom DataTemplates for the headers. We&#8217;re doing all sorts of crazy stuff with our headers and we need to preserve our DataTemplates, so this wasn&#8217;t an option. </p>
<p>In any case, I was having no luck finding the resource when I named it this way:</p>
<blockquote><p><span style="color: blue">&lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;MyCustomControlTemplate&quot; <span style="color: red">TargetType</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">GridViewColumnHeader</span><span style="color: blue">}&quot;&gt;</span></span></p>
</blockquote>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>I was using the following code to try and find the resource.</p>
<blockquote><p><span style="color: #2b91af">ControlTemplate </span>myNewTemplate = (<span style="color: #2b91af">ControlTemplate</span>)Resources[<span style="color: #a31515">&quot;MyCustomTemplate&quot;</span>];</p>
</blockquote>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>However, we were able to solve the problem by naming the resource this way</p>
<blockquote><p><span style="color: blue">&lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">ComponentResourceKey </span><span style="color: red">TypeInTargetAssembly</span><span style="color: blue">={</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">local</span><span style="color: blue">:</span><span style="color: red">MyCustomListView</span><span style="color: blue">}, </span><span style="color: red">ResourceId</span><span style="color: blue">=MyCustomControlTemplate}&quot;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue"><span style="color: red">TargetType</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">GridViewColumnHeader</span><span style="color: blue">}&quot;&gt;</span></span></p>
<p>   <a href="http://11011.net/software/vspaste"></a></p></blockquote>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>And then using this code to access it.</p>
<blockquote><p><span style="color: #2b91af">ComponentResourceKey </span>myCustomTemplateKey = <span style="color: blue">new </span><span style="color: #2b91af">ComponentResourceKey</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">SortableListView</span>), <span style="color: #a31515">&quot;MyCustomTemplate&quot;</span>);      <br /><span style="color: #2b91af">ControlTemplate </span>myNewTemplate = (<span style="color: #2b91af">ControlTemplate</span>)<span style="color: blue">this</span>.TryFindResource(myCustomTemplateKey);</p>
</blockquote>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>Just thought I&#8217;d pass it along.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/tip-for-finding-resources-for-a-control-in-genericxaml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Assign ColumnHeaderContainerStyle and ColumnHeaderTemplate to a ListView Style</title>
		<link>http://blogs.veracitysolutions.com/how-to-assign-columnheadercontainerstyle-and-columnheadertemplate-to-a-listview-style/</link>
		<comments>http://blogs.veracitysolutions.com/how-to-assign-columnheadercontainerstyle-and-columnheadertemplate-to-a-listview-style/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 23:06:06 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[How To...]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[Styles]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[columnheadercontainerstyle]]></category>
		<category><![CDATA[columnheadertemplate]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/08/15/how-to-assign-columnheadercontainerstyle-and-columnheadertemplate-to-a-listview-style/</guid>
		<description><![CDATA[This is just a quick note on creating a ListView style with the appropriate GridView style and template assignments.
Normally, I&#8217;ve been creating listviews that look like this:


&#60;ListView x:Name=&#8221;MyListView&#8221;
               ItemContainerStyle=&#8221;{DynamicResource MyListViewItemContainerStyle}&#8221;&#62;
    &#60;ListView.View&#62;
         &#60;GridView ColumnHeaderContainerStyle=&#8221;{DynamicResource MyListViewHeaderStyle}&#8221;
                         ColumnHeaderTemplate=&#8221;{DynamicResource MyGridColumnHeaderTemplate}&#8221;&#62; 
I did this because I didn&#8217;t know exactly how to assign these styles and templates to the ListView Style. In [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick note on creating a ListView style with the appropriate GridView style and template assignments.</p>
<p>Normally, I&#8217;ve been creating listviews that look like this:</p>
<blockquote>
<pre class="code"><span style="color: blue"></span></pre>
<p><span style="color: blue">&lt;</span><span style="color: #a31515">ListView </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&#8221;MyListView&#8221;</span><span style="color: red"><br />
               ItemContainerStyle</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyListViewItemContainerStyle</span><span style="color: blue">}&#8221;&gt;<br />
    </span><span style="color: blue">&lt;</span><span style="color: #a31515">ListView.View</span><span style="color: blue">&gt;<br />
         </span><span style="color: blue"><span style="color: blue">&lt;</span><span style="color: #a31515">GridView </span><span style="color: red">ColumnHeaderContainerStyle</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyListViewHeaderStyle</span><span style="color: blue">}&#8221;<br />
                         </span></span><span style="color: blue"><span style="color: red">ColumnHeaderTemplate</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyGridColumnHeaderTemplate</span><span style="color: blue">}&#8221;&gt;</span></span><span style="color: blue"> </span></p></blockquote>
<p><span style="color: blue"><font color="#000000">I did this because I didn&#8217;t know exactly how to assign these styles and templates to the ListView Style. In the style, ColumnHeaderContainerStyle and ColumnHeaderTemplate are not properties of the ListView, they are properties of the GridView&#8230; which you can&#8217;t create a style for.</font></span></p>
<p><span style="color: blue"><font color="#000000">Instead, you can encapsulate all the information above in the following style.</font></span></p>
<blockquote><p><span style="color: blue">&lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&#8221;CustomListViewStyle&#8221; </span><span style="color: red">TargetType</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">ListView</span><span style="color: blue">}&#8221;&gt;<br />
      &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;GridView.ColumnHeaderContainerStyle&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyListViewHeaderStyle</span><span style="color: blue">}&#8221; /&gt;<br />
      </span><span style="color: blue">&lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;GridView.ColumnHeaderTemplate&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyGridColumnHeaderTemplate</span><span style="color: blue">}&#8221; /&gt;<br />
      </span><span style="color: blue">&lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;ItemContainerStyle&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyListViewItemContainerStyle</span><span style="color: blue">}&#8221; /&gt;<br />
<span style="color: blue">&lt;/</span><span style="color: #a31515">Style&gt;</span></span></p></blockquote>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><span style="color: blue"><font color="#000000">Problem solved.</font></span></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-to-assign-columnheadercontainerstyle-and-columnheadertemplate-to-a-listview-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I Make a ListView or a ScrollViewer Left Handed?</title>
		<link>http://blogs.veracitysolutions.com/how-do-i-make-a-listview-or-a-scrollviewer-left-handed/</link>
		<comments>http://blogs.veracitysolutions.com/how-do-i-make-a-listview-or-a-scrollviewer-left-handed/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 05:40:32 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[ScrollViewer]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[left handed]]></category>
		<category><![CDATA[lefty]]></category>
		<category><![CDATA[scrollbar]]></category>
		<category><![CDATA[Triggers]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/04/18/how-do-i-make-a-listview-or-a-scrollviewer-left-handed/</guid>
		<description><![CDATA[Several months back, I was doing some work for a company that was using WPF for a stylus based application. One of the things that they found they needed was a scrollbar that could be used by left handed people who would have to cover the entire screen with their left hand in order to [...]]]></description>
			<content:encoded><![CDATA[<p>Several months back, I was doing some work for a company that was using WPF for a stylus based application. One of the things that they found they needed was a scrollbar that could be used by left handed people who would have to cover the entire screen with their left hand in order to scroll a traditional scroll viewer.</p>
<p>The solution ended up being so easy in WPF that I thought I&#8217;d post it here.</p>
<p>I&#8217;m in a two-birds-one-stone mood, so we&#8217;ll do this for both the listview, which will also cover a more traditional scrollviewer. Let&#8217;s start with our ever friendly listview.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/normallistview.png" alt="NormalListView" />At the very sight of this thing, with a stylus in hand, your average lefty is thinking to him or herself &#8220;I wonder if I can do my work upside down?&#8221; Let&#8217;s show them that we love and accept them just as they are.</p>
<p>The first thing we&#8217;re going to do is create a new template for this sucker, so right click on your listview and go to &#8220;<strong>Edit Control Parts (Template) -&gt; Edit a Copy…</strong>&#8221;</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/lefty_editcontrolparts.png" alt="Lefty_EditControlParts" /></p>
<p>Now we&#8217;re looking at the standard listview template. Mine looks like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/lefty_listviewtemplate.png" alt="ListViewTemplate" />Let&#8217;s dig right into the ScrollViewer. If you&#8217;re doing this from the listview (like I am) then creating a template for the listview has already created a template for the scrollviewer. If you&#8217;re starting from a basic scrollviewer, you can pretty much start right here.</p>
<p>For the purposes of making this thing easy to work with in Blend, go ahead and set the HorizontalScrollBarVisibility and VerticalScrollBarVisibility to Visible.</p>
<p> <img src="http://www.designerwpf.com/wp-content/uploads/2008/04/scrollbarvisibiltiy.png" alt="ScrollBar_Visibility" /></p>
<p>And then &#8220;<strong>Edit Control Parts (Template) -&gt; Edit a Copy…</strong>&#8221; (or &#8220;<strong>Edit Control Parts (Template) -&gt; Edit Template</strong>&#8221; if it is available).</p>
<p>We are now looking at the guts of the ScrollViewer Control.</p>
<p>ListView ScrollViewer will look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/listviewscrolltemplate.png" alt="ListViewScrollTemplate" />The normal ScrollViewer will look like this:</p>
<p> <img src="http://www.designerwpf.com/wp-content/uploads/2008/04/lefty_normalscrollviewer.png" alt="NormalScrollViewer" /></p>
<p>For our purposes, they&#8217;re functionally the same. It is actually a fairly simple control… basically just a Grid panel with the columns and rows set up like so:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">*</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">Auto</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font></p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Grid.RowDefinitions</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">RowDefinition</font> <font color="#ff0000">Height</font>=&#8221;<font color="#0000ff">*</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">RowDefinition</font> <font color="#ff0000">Height</font>=&#8221;<font color="#0000ff">Auto</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Grid.RowDefinitions</font><font color="#0000ff">&gt;</font></p>
<p>The scrollBars are set up so that their visibility is tied to (duh) the visibility that is set on the control. But what this does is it means that when they are collapsed… they Grid reclaims the space that they were taking up.</p>
<p>Now… here&#8217;s the hilarious part… in order to make this ScrollViewer left handed, all you have to do is swap the Grid.Columns:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">Auto</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">*</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font></p>
<p>You&#8217;ve now switched the columns so that the left handed column is auto. Here&#8217;s a list of the Grid.Column realignments you&#8217;ll need to make:</p>
<p><strong>Change Column to &#8220;1&#8243;:</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/lefty_columnswitch1.png" alt="Lefty_Column1" /></p>
<ul>
<li>PART_HorizontalScrollBar</li>
<li>All DockPanels (ListView only)</li>
<li>PART_ScrollContentPresenter (ScrollViewer only)</li>
<li>Corner (ScrollViewer only)</li>
</ul>
<p><strong>Change Column to &#8220;0&#8243;:</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/lefty_columnswitch0.png" alt="Lefty_Column0" /></p>
<ul>
<li>PART_VerticalScrollBar</li>
</ul>
<p>Basically, swap everything from in the two columns.</p>
<p>Done.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/04/finalleftyproduct.png" alt="FinalLeftyListView" />If you want to make this a more robust control, I recommend creating a ScrollViewer with an additional dependency property (IsSouthPaw or something). Make it so that your Grid has three columns:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">Auto</font>&#8220;<font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">ColumnDefinition</font> <font color="#ff0000">Width</font>=&#8221;<font color="#0000ff">*</font>&#8220;<font color="#0000ff">/&gt;<br />
      &lt;<font color="#800000">ColumnDefinition</font><font color="#000000"> </font><font color="#ff0000">Width</font><font color="#000000">=&#8221;</font><font color="#0000ff">Auto</font><font color="#000000">&#8220;</font><font color="#0000ff">/&gt;</font></font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Grid.ColumnDefinitions</font><font color="#0000ff">&gt;</font></p>
<p>And then you can just create a trigger that swaps the column placement of your PART_VerticalScrollBar. Such a trigger will look something like this. And by &#8220;something&#8221;, I mean &#8220;exactly&#8221;.</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Trigger</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">IsSouthPaw</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">True</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Grid.Column</font>&#8221; <font color="#ff0000">TargetName</font>=&#8221;<font color="#0000ff">PART_VerticalScrollBar</font>&#8220;  <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">0</font>&#8221; <font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Trigger</font><font color="#0000ff">&gt;</font></p>
<p>Go forth and make Ned Flanders proud.</p>
<p>By the way, I listen to pop punk whenever I write my tutorials and I just thought I should let <a href="http://en.wikipedia.org/wiki/Senses_Fail">Senses Fail </a>know that they can probably get away with about 80% less &#8220;dying cat&#8221; screaming and still put out good music. You know&#8230; because they&#8217;re probably WPF programmers on the side and they&#8217;ll probably read this to solve all their left-handed scrollbar needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-do-i-make-a-listview-or-a-scrollviewer-left-handed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Designers Guide to Styles And Templates</title>
		<link>http://blogs.veracitysolutions.com/wpf-designers-guide-to-styles-and-templates/</link>
		<comments>http://blogs.veracitysolutions.com/wpf-designers-guide-to-styles-and-templates/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 20:45:04 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Styles]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Designer Guides]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/03/27/wpf-designers-guide-to-styles-and-templates/</guid>
		<description><![CDATA[This is a post that has taken months to complete, but addresses something that I don’t think I&#8217;ve seen sufficiently covered for anyone who is new to WPF. Resultantly, we&#8217;re going to go through it slowly and I&#8217;m officially begging for additional questions at the end.
Part of the problem with styles and templates in WPF [...]]]></description>
			<content:encoded><![CDATA[<p>This is a post that has taken months to complete, but addresses something that I don’t think I&#8217;ve seen sufficiently covered for anyone who is new to WPF. Resultantly, we&#8217;re going to go through it slowly and I&#8217;m officially begging for additional questions at the end.</p>
<p>Part of the problem with styles and templates in WPF stems from the fact that Blend allows a wonderfully simply way of creating a copy of a template:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_editcontrolparts.png" alt="SNT_EditControlParts" /></p>
<p>It then gives you something that looks like this:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">My_Template</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Template</font>&#8220;<font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">Setter.Value</font><font color="#0000ff">&gt;<br />
</font>                  <font color="#0000ff">&lt;</font><font color="#800000">ControlTemplate</font> <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8220;<font color="#0000ff">&gt;</font><br />
                        <font color="#008000">&lt;!&#8211; blah blah blah &#8211;&gt;</font></p>
<p>So, from a usability point of view… I told it to create a Template and it created a style. I judged from this that styles and templates were roughly the same thing.</p>
<p>And I was confused.</p>
<p>So, first, I&#8217;ll try to explain styles and templates by explaining how they work and then I&#8217;ll draw an analogy that I hope is helpful.</p>
<p>Let&#8217;s say you have a button.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_basicbtn.png" alt="Hi_Button" /></p>
<p>You can change all sorts of properties of that button… visibility, background, width, height, margins, border thickness, alignment, font, whatever.</p>
<p>If you have a dozen buttons and you want them all to have the same properties, you can create a button style that specifies those properties and assigns them across the board. You can edit a style in Blend by selecting your control, clicking in the menu: &#8220;<strong>Objects -&gt; Edit Style -&gt; Edit a Copy…</strong>&#8220;.</p>
<p>Style editing in the objects tab will look like this.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_styleobjects.png" alt="Style_Objects" /></p>
<p>As you can see, there are no objects in the visual tree to play with… only properties to assign in the properties tab.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_styleproperties.png" alt="Button_Style_Properties" /></p>
<p>When you assign a property in Blend, your styles will save that assignment as setters and values. Let&#8217;s say we wanted all of our buttons to have green 18 point font  bold text. We could create a style that looked like this:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">GreenBorderButton</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Foreground</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">#FF00FF00</font>&#8221; <font color="#0000ff">/&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">FontSize</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">18</font>&#8220;<font color="#0000ff"> /&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">FontWeight</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">Bold</font>&#8221; <font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">Style</font><font color="#0000ff">&gt;</font></p>
<p>The styles can only define properties that belong to the control type that they are styling (which is defined in the &#8220;<strong>TargetType</strong>&#8220;). Also, styles can only give information for properties the control already has and only in the way that the control is already set up. For example, because there is no property for changing the corner radius of a button, you can&#8217;t change the corner radius of a button using a button style.</p>
<p>However, what if we want to change something about the button that we can&#8217;t change with the given properties? For example, let&#8217;s say we wanted to see all the text show up twice.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_doublebtn.png" alt="Double_Button" /></p>
<p>In order to do this, we need to make what I&#8217;m going to call &#8220;structural changes&#8221; to our control. Structural changes are changes in the actual guts of the control, changes to the base elements that make up the control. For this we need a control template.</p>
<p>Boiled down to their essence, templates are little chunks of XAML that are inserted whenever you use your control. When you right click on something and go to  &#8220;<strong>Edit Control Parts (Template) -&gt; Edit a Copy…</strong>&#8220;, Blend takes the default XAML that makes up your control and places it in the resources so that you can change it at your whim.</p>
<p>You can get to the Control Template using the right-click method described at the top of this post. Your basic button template will look something like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_btntemplate.png" alt="Button_Template" /></p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Style</font><font color="#ff0000"> x:Key</font>=&#8221;<font color="#0000ff">MyButtonStyle</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Template</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#b8860b">{DynamicResource MyButtonTemplate}</font>&#8221; <font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">&lt;/</font><font color="#800000">Style</font><font color="#0000ff">&gt;</font></p>
<p><font color="#0000ff">&lt;</font><font color="#800000">ControlTemplate</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">MyButtonTemplate</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8221; <font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Microsoft_Windows_Themes:ButtonChrome</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">Chrome</font>&#8221; <font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">ContentPresenter</font> <font color="#0000ff">/&gt;<br />
</font>      <font color="#0000ff">&lt;/</font><font color="#800000">Microsoft_Windows_Themes:ButtonChrome</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">ControlTemplate</font><font color="#0000ff">&gt;</font></p>
<p>We can go in and add an additional ContentPresenter in here, like so:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">ControlTemplate</font><font color="#ff0000"><font color="#800000"> </font>x:Key</font>=&#8221;<font color="#0000ff">MyButtonTemplate</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Button}</font>&#8221; <font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Microsoft_Windows_Themes:ButtonChrome</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">Chrome</font>&#8221; <font color="#0000ff">&gt;<br />
</font>            <font color="#0000ff">&lt;</font><font color="#800000">Grid</font><font color="#0000ff">&gt;<br />
</font>                  <font color="#0000ff">&lt;</font><font color="#800000">Grid.RowDefinitions</font><font color="#0000ff">&gt;</font><br />
                        <font color="#0000ff">&lt;</font><font color="#800000">RowDefinition</font> <font color="#ff0000">Height</font>=&#8221;<font color="#0000ff">.5*</font>&#8221; <font color="#0000ff">/&gt;<br />
</font>                        <font color="#0000ff">&lt;</font><font color="#800000">RowDefinition</font> <font color="#ff0000">Height</font>=&#8221;<font color="#0000ff">.5*</font>&#8221; <font color="#0000ff">/&gt;</font><br />
                  <font color="#0000ff">&lt;</font><font color="#800000">Grid.RowDefinitions</font><font color="#0000ff">&gt;</font><br />
                  <font color="#0000ff">&lt;</font><font color="#800000">ContentPresenter</font> <font color="#ff0000">Grid.Row</font>=&#8221;<font color="#0000ff">0</font>&#8221; <font color="#0000ff">/&gt;</font><br />
                  <font color="#0000ff">&lt;</font><font color="#800000">ContentPresenter</font> <font color="#ff0000">Grid.Row</font>=&#8221;<font color="#0000ff">1</font>&#8221; <font color="#0000ff">/&gt;</font><br />
            <font color="#0000ff">&lt;/</font><font color="#800000">Grid</font><font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;/</font><font color="#800000">Microsoft_Windows_Themes:ButtonChrome</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">ControlTemplate</font><font color="#0000ff">&gt;</font></p>
<p>And now our button shows all the content twice, one right on top of another.</p>
<p>The best way I&#8217;ve found to think about it is to think of your control as a car.</p>
<p>The dealer give the buyer a list of things that they can change about the car… interior color, leather or fabric seats, 4 or 6 cylinder engine… these are properties of the car… defined in the car &#8220;style&#8221;. (Basically, you can think of everything that you&#8217;re allowed to tweak <a href="http://www.toyota.com/byt/pub/setStartOptions.do?seriesCategory=3&amp;zipHolder=&amp;modelId=&amp;zipEditInputTextField=&amp;zipCode=84124">at this website </a>as the style of the car.)</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Style</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">MySpecialCar</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Camry}</font>&#8221; <font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">ExteriorColor</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">Blue</font>&#8221; <font color="#0000ff">/&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter </font><font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">TransmissionType</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">5SpeedManual</font>&#8221; <font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">&lt;/</font><font color="#800000">Style</font><font color="#0000ff">&gt;</font></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/03/snt_camerybasic.png" alt="Camery_Basic" /><br />
<br />
But let&#8217;s say that the buyer doesn&#8217;t want a normal seat… she wants a big comfy chair in place of the regular drivers seat. This is something outside of the scope of the list of things she was allowed to choose from, so they have to draw up new blueprints for making this new car. They have to create a new car &#8220;template&#8221;.</p>
<p>If our normal Camry blueprint looks like this:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">ControlTemplate</font> <font color="#ff0000">x:Key</font>=&#8221;<font color="#0000ff">MySpecialCarBlueprint</font>&#8221; <font color="#ff0000">TargetType</font>=&#8221;<font color="#b8860b">{x:Type Camry}</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">CamryFrame</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">CamryFrame</font>&#8221; <font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">Seat</font> <font color="#ff0000">Type</font>=&#8221;<font color="#0000ff">Drivers</font> &#8221; <font color="#0000ff">/&gt;<br />
</font>            <font color="#0000ff">&lt;</font><font color="#800000">Seat</font> <font color="#ff0000">Type</font>=&#8221;<font color="#0000ff">FrontPassenger</font>&#8221; <font color="#0000ff">/&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">Seat</font> <font color="#ff0000">Type</font>=&#8221;<font color="#0000ff">BackBench</font>&#8221; <font color="#0000ff">/&gt;</font><br />
      <font color="#0000ff">&lt;/</font><font color="#800000">CamryFrame</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">&lt;<font size="+0">/</font></font><font color="#800000">ControlTemplate</font><font color="#0000ff">&gt;</font></p>
<p>We can go in and replace :</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Seat</font> <font color="#ff0000">Type</font>=&#8221;<font color="#0000ff">Drivers</font> &#8221; <font color="#0000ff">/&gt;</font></p>
<p>With</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Seat</font> <font color="#ff0000">Type</font>=&#8221;<font color="#0000ff">ComfyChair</font>&#8221; <font color="#0000ff">/&gt;</font></p>
<p><img width="198" src="http://www.designerwpf.com/wp-content/uploads/2008/03/comfychair.png" alt="ComfyChair" height="154" /></p>
<p>You may also notice that, with this model we could get rid of all the other seats except the drivers seat or we could add 12 new rows of seats. We can change anything about the car because we&#8217;re down into the original car blueprint.</p>
<p><strong>This is the basic difference between styles and templates. </strong></p>
<ul>
<li>A<em> style</em> is a list of properties that can be assigned in bulk to a control.</li>
<li>A<em> template</em> goes a big step further and actually defines the underlying structure of the control.</li>
</ul>
<p>You may be asking: &#8220;So how do these two work together? And what is this Data Template think I keep hearing about?&#8221;</p>
<p>Given that this post is getting dangerously long already, I&#8217;m going to address those issues in a couple more posts on styles and templates.</p>
<p>I&#8217;ll end on this note: if you are working in WPF and you&#8217;re having trouble with styles and templates, please read all of these posts (as I get to them) and ask questions in the comments section. I&#8217;m pretty good about getting to the comments questions and if the question is big enough, I&#8217;ll write a whole post on it. There are few things more vital to a WPF developer/designer than to have a firm grasp on styles and templates. It is in this understanding that the power of WPF really comes out.</p>
<ul>
<li>Who&#8217;s The Boss? Property Priority in Styles and Templates (coming soon)</li>
<li>Create Conditional Styles and Templates (With the Magic of Triggers) (coming soon)</li>
<li>So How Do Data Templates Fit Into All This? (coming soon)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/wpf-designers-guide-to-styles-and-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Drop-Shadows on The Cheap</title>
		<link>http://blogs.veracitysolutions.com/wpf-drop-shadows-on-the-cheap/</link>
		<comments>http://blogs.veracitysolutions.com/wpf-drop-shadows-on-the-cheap/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 00:12:16 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/02/08/wpf-drop-shadows-on-the-cheap/</guid>
		<description><![CDATA[One of the questions I get most often from designers and almost never from developers is:
How can I get drop shadows into my application without killing my performance?
 It is, of course, easy as punch and pie to get drop shadows into your application. You can just use the Bitmaps Effects panel in the Appearance section:
 
For [...]]]></description>
			<content:encoded><![CDATA[<p>One of the questions I get most often from designers and almost never from developers is:</p>
<p><strong>How can I get drop shadows into my application without killing my performance?</strong></p>
<p> It is, of course, easy as punch and pie to get drop shadows into your application. You can just use the Bitmaps Effects panel in the Appearance section:</p>
<p> <img src="http://www.designerwpf.com/wp-content/uploads/2008/02/ordinarydropshadow.png" alt="OrdinaryDropShadowing" /></p>
<p><em>For the love of God, please do not use the Bitmap Effects in the Appearance section!</em></p>
<p>If any developers found out that I told you to use BitmapEffects, they would hunt me down and cut off my fingers. This is because, while the Bitmap Effects in WPF are all sorts of cool, they make your computer break down into uncontrollable sobbing. Bitmap Effects hog system resources by requiring software rendering for render-heavy effects. There is no better way to slow down a perfectly good application than to give every other element a drop shadow.</p>
<p>But, what if you really <em>really</em> want to?</p>
<p><span id="more-244"></span></p>
<p>That is why there is this handy little thing called a &#8220;SystemDropShadowChrome&#8221;. The way to use it is to put the following namespace into your Window tag:</p>
<p><font color="#0000ff">xmlns:dropShadow</font>=&#8221;<font color="#ff0000">clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero</font>&#8221;<br />
<br />
And then take the thing you want to have a drop shadow and wrap it in a SystemDropShadowChrome like so:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">dropShadow:SystemDropShadowChrome</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">      &lt;</font><font color="#800000">Grid</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">MyElement</font>&#8221; <font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">dropShadow:SystemDropShadowChrome</font><font color="#0000ff">&gt;</font></p>
<p>So what are we losing when we do this?</p>
<p>Normal bitmap dropshadows give you the following options:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/ordinarydropshadowoptions.png" alt="OrdinaryDropShadowOptions" /></p>
<p>And they conform to the item to which they are attached. It could be bannana-shaped… you would get a banana-shaped drop shadow.</p>
<p>But with SystemDropShadowChrome, you get a rectangle and the ability to choose the color of your drop-shadow and the corner-radius. That&#8217;s it. But that gives you a decent amount of room to work with. Consider what <a href="http://notstatic.com/archives/68">Robby Ingebretsen did in his example on SystemDropShadowChrome </a>(magnified 2X):</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/dropshadowexamples.png" alt="EasyDropShadowExamples" /></p>
<p>We&#8217;ve got darker drop shadows, lighter drop shadows, colored drop shadows and a drop shadow with an irregular corner radius. This is flexible enough for pretty much any standard application control. Used in templates, you could even use this to give drop shadow to just one part of the control. In fact, my attention was first drawn to the use of the drop shadow in the Popup part of the ComboBox control.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/comboboxdropshadowexample.png" alt="ComboBoxDropShadowExample" /></p>
<p>You can change the drop shadow color using a standard color picker in the &#8220;Miscellaneous&#8221; section of the SystemDropShadowChrome properties in Blend:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/colorpickerdropshadow.png" alt="DropShadowColorPickerExample" /></p>
<p>This is also where you can find the &#8220;CornerRadius&#8221; property. In the XAML, they will look like this:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">dropShadow:SystemDropShadowChrome</font> <font color="#ff0000">CornerRadius</font>=&#8221;<font color="#0000ff">3,13,3,13</font>&#8221; <font color="#ff0000">Color</font>=&#8221;<font color="#0000ff">#71000000</font>&#8220;<font color="#0000ff">&gt;</font><br />
<font color="#0000ff"><font color="#000000">      </font>&lt;</font><font color="#800000">Grid</font> <font color="#ff0000">x:Name</font>=&#8221;<font color="#0000ff">MyElement</font>&#8221; <font color="#0000ff">/&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">dropShadow:SystemDropShadowChrome</font>&gt;</p>
<p>With some creative styling, we can actually change the direction of the drop shadow. It&#8217;s easy enough to do if you&#8217;re just hacking away, but if you plan on using it seriously in an application, it requires some forethought and organization, so I&#8217;ll go into that in detail in a full post on changing the SystemDropShadowChrome direction. (coming soon)</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/wpf-drop-shadows-on-the-cheap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I Style The ComboBox Items?</title>
		<link>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/</link>
		<comments>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 06:45:21 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Combobox]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[itemcontainerstyle]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[Triggers]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/02/07/how-do-i-style-the-combobox-items/</guid>
		<description><![CDATA[This is actually a continuation of my post on getting the ComboBox items to accept text wrapping, so I&#8217;ll be working from that point forward. If you&#8217;re coming fresh into this, you won&#8217;t be missing anything&#8230; but that is my explaination for the pictures containing wrapping text.
When last we left our heroes, we has a [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually a continuation of my post on <a href="http://www.designerwpf.com/2008/02/04/how-do-i-wrap-text-in-the-combobox/">getting the ComboBox items to accept text wrapping</a>, so I&#8217;ll be working from that point forward. If you&#8217;re coming fresh into this, you won&#8217;t be missing anything&#8230; but that is my explaination for the pictures containing wrapping text.</p>
<p>When last we left our heroes, we has a couple problems. The first was that our items were either black text on a white background and ran together in a very un-designer-y way.</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/basicview.png" alt="BeginningViewComboStyling" /></p>
<p>The second was that the selected item background makes your eyes bleed such a horrid blue color you&#8217;ll feel like Paul Atreides staring at a stone burner.</p>
<p>Was that a little too geek? My apologies.</p>
<p><span id="more-236"></span></p>
<p>Anyway, let&#8217;s do something to make this control a little more usable (as well as easier on our eyes).</p>
<p>Highlight your ComboBox and go up to the toolbar, selecting <strong>Object -&gt; Edit Other Styles -&gt; Edit ItemContainerStyle -&gt; Edit a Copy…</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/itemcontainerstylemenu.png" alt="ItemContainerStyleMenuCombo" /></p>
<p>We&#8217;re now in the ItemContainerStyle editing mode. I really just need some demarcation between the items, so I&#8217;m going to give the items a BorderBush with a gradient that has a nice blue at the top and fades down to transparency at the bottom. It looks something like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/borderbrushgradient.png" alt="BorderBrushGradient" /></p>
<p>We will, of course, want our users to see this border, so let&#8217;s give the style a BorderThickness of 1 all around and a Margin of 4 to offer a little space. Our items now look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/stylework.png" alt="ComboboxItemsStylingWork" /></p>
<p>Better… but we don&#8217;t see the trigger for that hideous shade of blue in the style, so we need to go somewhere else to change it. Right click on the Style and go to <strong>Edit ControlParts (Template) -&gt; Edit Template</strong></p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/templatemenu.png" alt="TemplateMenu" /></p>
<p>We can see that the template here is exceedingly dull… just a border surrounding a ContentPresenter. We like dull. Dull means it&#8217;s not complex. First, let&#8217;s do some polishing up… give that border a CornerRadius of 5. Keep in mind that this is Vista-based development… no sharp corners allowed.</p>
<p>Now, let&#8217;s kill that blue. Click on the <strong>&#8220;IsHighlighted = True&#8221;</strong> trigger at the top…</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/ishighlightedtrigger.png" alt="IsHighlightedTrigger" /></p>
<p>..and we can see the highlighted state. I changed the Background to a nice soft blue gradient (you can change it to a deep purple with a green bubble for all I care… it&#8217;s WPF, go nuts!) This would be great except that I can&#8217;t see the Foreground now, so let&#8217;s change that to make the text readable.</p>
<p> I couldn&#8217;t figure out how to do this in the design mode, so find the IsHighlighted Trigger in the XAML and insert the bold text below:</p>
<p><font color="#0000ff">&lt;</font><font color="#800000">Trigger</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">IsHighlighted</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">true</font>&#8220;<font color="#0000ff">&gt;</font><br />
      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Foreground</font>&#8221; <font color="#ff0000">Value</font>=&#8221;<font color="#0000ff">#FF001720</font>&#8220;<font color="#0000ff">/&gt;<br />
</font>      <font color="#0000ff">&lt;</font><font color="#800000">Setter</font> <font color="#ff0000">Property</font>=&#8221;<font color="#0000ff">Background</font>&#8221; <font color="#ff0000">TargetName</font>=&#8221;<font color="#0000ff">Bd</font>&#8220;<font color="#0000ff">&gt;<br />
      &#8230;</font></p>
<p>Now our ComboBox items look like this:</p>
<p><img src="http://www.designerwpf.com/wp-content/uploads/2008/02/finalcomboboxitems.png" alt="FinalComboBoxItems" /></p>
<p>Much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/how-do-i-style-the-combobox-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
